package com.moduls.interfaceFunction.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Date;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.ibatis.session.SqlSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

import com.aliyuncs.exceptions.ClientException;
import com.moduls.interfaceFunction.alipay.config.AlipayConfig;
import com.moduls.interfaceFunction.core.HtmlUtils;
import com.moduls.interfaceFunction.core.Result;
import com.moduls.interfaceFunction.core.SqlMapper;
import com.moduls.interfaceFunction.message.MessageController;
import com.moduls.interfaceFunction.model.Systemmessage;
import com.moduls.interfaceFunction.weixin.pay.WeixinPay;
import com.moduls.push.UPushUtils;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class WxhtAction {
	//上传文件路径
	public static String filesave_path =  "http://121.42.231.1:8180/";
	public static String app_download =  "https://www.pgyer.com/zKHE";
	public HttpServletRequest request;
	public HttpServletResponse response;
	private final Logger logger =  LoggerFactory.getLogger(WxhtAction.class);
	@Autowired
	public SqlSession sqlSessions;
	private JSONObject obj_vars;
	public Result results= new Result();
	public basictool basictool =  new basictool();
	//引入替换html代码类
	public HtmlUtils htmlUtils= new HtmlUtils();
	public JSONObject getObj_vars() {
		return obj_vars;
	}
	public void setObj_vars(JSONObject obj_vars) {
		this.obj_vars =  obj_vars;
	}
	//接口开始*******************************************************************
	// 接口功能：<font color= "red">注意注意注意：1.登陆后，需要验证的接口必须都传token和registerId和registerRole(所有接口都传也没关系)。state= 1请求成功state= 0请求失败 state= 2token过期重新登录 3密码错误或已锁定账户</font>
	public void api_readme() throws IOException, SQLException {

	}
	// 接口功能：验证码（用户端）（写列为1111）(ok)
	public void get_code() throws IOException, SQLException, ClientException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String phone =  obj_vars.optString("phone"); //账号（手机号）
		String type =  obj_vars.optString("type"); //短信场景（1用户方注册 2用户方修改密码,3服务方修改密码  4用户方第三方登录 手机验证）
		int res= 0;
		int status =  1;
		String message =  "";
		int ifexist= 0; //是否存在用户 0-否1-是
		switch (type) {
			case "1":
				if (sqlMapper.public_dataifexist("p_user", "phone= " + phone)) {
					status =  0;
					message =  "该手机号已被注册";
				}else {
					status =  1;
					message =  "发送成功";
				}
				break;
			case "2":
				if (!sqlMapper.public_dataifexist("p_user", "phone= " + phone)) {
					status =  0;
					message =  "该手机号未注册";
				}else {
					status =  1;
					message =  "发送成功";
				}
				break;
			case "3":
				if (!sqlMapper.public_dataifexist("s_provider", "phone= " + phone)) {
					status =  0;
					message =  "该手机号未注册";
				}else {
					status =  1;
					message =  "发送成功";
				}
				break;
			case "4":
				if (sqlMapper.public_dataifexist("p_user", "phone= " + phone)) {
					status =  1;
					message =  "发送成功";
					ifexist= 1;
				}else {
					status =  1;
					message =  "发送成功";
				}
				break;
		}
		if (status ==  1) {
			MessageController controller= new MessageController();
			Map<String, String> map = controller.setMessage(phone, type);
//				Map<String, String> map= new HashMap<>();
			message =  map.get("message");
//				message =  "发送成功";
			if(message.equals("发送成功")){
				res = sqlMapper.insert_or_update("p_sms", new HashMap<String, String>() {
					{
						put("sms_phone", map.get("sms_phone"));
						put("sms_code", map.get("sms_code"));
					}
				}, "");
				if(res<= 0){
					message = "保存失败";
					status =  0;
				}
			}else{
				status =  0;
			}

			if(type.equals("4")) {
				Map<String, Object> maps= new HashMap<>();
				maps.put("sms_id", res);
				maps.put("ifexist", ifexist);
				results.setResult(maps);
			}else {
				results.setResult(res);//输出：短信id
			}
			results.setMessage(message);//输出：提示信息
			results.setStatus(status);//输出：状态1成功 0失败

		}else {

			results.setMessage(message);
			results.setStatus(0);

		}
	}
	// 接口功能：注册(ok) 测试用 sms_id（验证码id）:1  sms_code（验证码）：1111
	public void register_set() throws IOException, SQLException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String phone =  obj_vars.optString("phone"); // 账号（手机号）
		String pwd =  obj_vars.optString("pwd"); // 密码
		String sms_id =  obj_vars.optString("sms_id"); // 验证码id
		String sms_code =  obj_vars.optString("sms_code"); // 验证码
		String real_name =  obj_vars.optString("real_name"); //真实姓名
		String card_id =  obj_vars.optString("card_id"); //身份证号
		String loc_lng =  obj_vars.optString("loc_lng"); //经度
		String loc_lat =  obj_vars.optString("loc_lat"); //纬度
		String DriverID =  obj_vars.optString("DriverID"); // android推送
		String IOSDriverID =  obj_vars.optString("IOSDriverID"); // ios推送
		Map<String, Object> code= sqlMapper.selectOne("select sms_code from p_sms where sms_id= "+sms_id+" and sms_phone= '"+phone+"'");
		if(sqlMapper.public_dataifexist("p_user"," phone = "+phone)) {
			results.setMessage("账号已存在！");
			results.setStatus(0);
		}else if(!sms_code.equals(code.get("sms_code"))){
			results.setMessage("验证码错误！");
			results.setStatus(0);
		}else {
			Map<String, String> map =  new HashMap<String, String>();
			map.put("phone", phone);
			map.put("pwd", basictool.MD5(pwd));
			map.put("real_name", real_name);
			map.put("card_id", card_id);
			map.put("loc_lng", loc_lng);
			map.put("loc_lat", loc_lat);
			map.put("DriverID", DriverID);
			map.put("IOSDriverID", IOSDriverID);
			String token =  UUID.randomUUID().toString();
			map.put("token", token);
			int res =  sqlMapper.insert_or_update("p_user", map, null);
			if(res>0) {
				results.setMessage("注册成功");
				results.setStatus(1);
				Map<String, Object> result =  sqlMapper.public_one_detail("p_user", new HashMap<String, String>() {
					{
						put("phone", phone);
						put("pwd", basictool.MD5(pwd));
					}
				});
				results.setResult(result);//输出：列表数据
			}else {
				results.setMessage("注册失败");//输出：提示信息
				results.setStatus(0);//输出：状态1成功 0失败
			}
		}

	}
	// 接口功能：修改密码(ok)
	public void editpwd_set() throws IOException, SQLException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String phone =  obj_vars.optString("phone"); // 账号（手机号,工号）
		String pwd =  obj_vars.optString("pwd"); // 密码
		String role =  obj_vars.optString("role"); // 1用户方 2服务方
		String sms_id =  obj_vars.optString("sms_id"); // 验证码id
		String sms_code =  obj_vars.optString("sms_code"); // 验证码
		if (!phone.equals("") && !pwd.equals("") && !role.equals("")) {
			switch (role) {
				case "1":
					boolean ifexist =  sqlMapper.public_dataifexist("p_user", "phone= "+phone+" and is_forbid= 0");
					if(ifexist) {
						String code= sqlMapper.selectOne("select sms_code from p_sms where sms_id= "+sms_id+" and sms_phone= '"+phone+"'").get("sms_code").toString();
						if(code.equals(sms_code)) {
							int res= sqlMapper.insert_or_update("p_user", new HashMap<String, String>() {
								{
									put("pwd", basictool.MD5(pwd));
								}
							}, "phone= "+phone);
							if(res>0) {
								results.setMessage("修改成功");
								results.setStatus(1);
							}else {
								results.setMessage("修改失败");
								results.setStatus(0);
							}

						}else {
							results.setMessage("验证码输入有误");
							results.setStatus(0);
						}
					}else {
						results.setMessage("账号密码错误或账号不可用");
						results.setStatus(0);
					}
					break;

				case "2":
					boolean ifexists =  sqlMapper.public_dataifexist("s_provider", "phone= "+phone+" and is_forbid= 0");
					if(ifexists) {
						String code= sqlMapper.selectOne("select sms_code from p_sms where sms_id= "+sms_id+" and sms_phone= '"+phone+"'").get("sms_code").toString();
						if(code.equals(sms_code)) {
							int res= sqlMapper.insert_or_update("s_provider", new HashMap<String, String>() {
								{
									put("pwd", basictool.MD5(pwd));
								}
							}, "phone= "+phone);
							if(res>0) {
								results.setMessage("修改成功");
								results.setStatus(1);
							}else {
								results.setMessage("修改失败");
								results.setStatus(0);
							}

						}else {
							results.setMessage("验证码输入有误");
							results.setStatus(0);
						}
					}else {
						results.setMessage("账号密码错误或账号不可用");
						results.setStatus(0);
					}
					break;
			}
		} else {
			results.setMessage("参数错误");//输出：提示信息
			results.setStatus(0);//输出：状态1成功 0失败
		}
	}
	// 接口功能：登陆(ok)
	public void login_get() throws IOException, SQLException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String phone =  obj_vars.optString("phone"); // 账号（手机号,工号）
		String pwd =  obj_vars.optString("pwd"); // 密码
		String role =  obj_vars.optString("role"); // 1用户方 2服务方
		String DriverID =  obj_vars.optString("DriverID"); // android推送
		String IOSDriverID =  obj_vars.optString("IOSDriverID"); // ios推送
		if (!phone.equals("") && !pwd.equals("") && !role.equals("")) {
			switch (role) {
				case "1":
					Map<String, Object> Result =  sqlMapper.public_one_detail("p_user", new HashMap<String, String>() {
						{
							put("phone", phone);
							put("pwd", basictool.MD5(pwd));
						}
					});
					if (Result== null) {
						results.setMessage("密码错误");
						results.setStatus(0);
					} else {
						if(Result.get("is_forbid").equals(0)){
							String token =  UUID.randomUUID().toString();
							sqlMapper.insert_or_update("p_user", new HashMap<String, String>() {
								{
									put("token", token);
									put("last_login_time",sqlMapper.public_getcurrenttime());
									put("DriverID", DriverID);
									put("IOSDriverID", IOSDriverID);
								}
							}, "uid= " + Result.get("uid").toString());
							Result.put("token", token);
							results.setResult(Result);
							results.setMessage("登录成功");
							results.setStatus(1);
//						mapoutput.put("fileRoot_path", fileRoot_path);//输出：图片根路径（保存下来，后面都用这个）
						}else{
							results.setMessage("账号不可用");
							results.setStatus(3);
						}
					}
					break;
				case "2":
					Map<String, Object> Resultwo =  sqlMapper.public_one_detail("s_provider", new HashMap<String, String>() {
						{
							put("work_no", phone);
							put("pwd", basictool.MD5(pwd));
							put("is_forbid", "0");
						}
					});
					if (Resultwo== null) {
						results.setMessage("账号密码错误或账号不可用");
						results.setStatus(0);
					} else {
						String token =  UUID.randomUUID().toString();
						sqlMapper.insert_or_update("s_provider", new HashMap<String, String>() {
							{
								put("token", token);
								put("last_login_time",sqlMapper.public_getcurrenttime());
								put("DriverID", DriverID);
								put("IOSDriverID", IOSDriverID);
							}
						}, "pid= " + Resultwo.get("pid").toString());
						Resultwo.put("token", token);
						results.setResult(Resultwo);//输出：列表数据
						results.setMessage("登录成功");
						results.setStatus(1);
//						mapoutput.put("fileRoot_path", fileRoot_path);//输出：图片根路径（保存下来，后面都用这个）
					}
					break;
			}
		} else {
			results.setMessage("参数错误");//输出：提示信息
			results.setStatus(0);//输出：状态1成功 0失败
		}
	}
	// 接口功能：用户方第三方登录
	public void other_login_get() throws IOException, SQLException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String qq =  obj_vars.optString("qq"); // qq号 id
		String wx =  obj_vars.optString("wx"); // wx号 id
		String DriverID =  obj_vars.optString("DriverID"); // android推送
		String IOSDriverID =  obj_vars.optString("IOSDriverID"); // ios推送
		Map<String, Object> Resulone= new HashMap<>();
		if(!qq.isEmpty()) {
			Resulone =  sqlMapper.public_one_detail("p_user", new HashMap<String, String>() {
				{
					put("qq", qq);
				}
			});
		}
		if(!wx.isEmpty()) {
			Resulone =  sqlMapper.public_one_detail("p_user", new HashMap<String, String>() {
				{
					put("wx", wx);
				}
			});
		}
		if(Resulone!= null) {
			if(Resulone.get("is_forbid").equals(0)) {
				String token =  UUID.randomUUID().toString();
				sqlMapper.insert_or_update("p_user", new HashMap<String, String>() {
					{
						put("token", token);
						put("last_login_time",sqlMapper.public_getcurrenttime());
						put("DriverID", DriverID);
						put("IOSDriverID", IOSDriverID);
					}
				}, "uid= " + Resulone.get("uid").toString());
				Resulone.put("token", token);
				results.setResult(Resulone);//输出：列表数据
				results.setMessage("登录成功");
				results.setStatus(1);
			}else {
				results.setMessage("账号已被禁用，请联系平台");
				results.setStatus(3);
			}
		}else {
			results.setMessage("需要绑定手机号");
			results.setStatus(1);
		}
	}
	// 接口功能：用户方第三方登录-绑定手机号
	public void other_setphone() throws IOException, SQLException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String qq =  obj_vars.optString("qq"); // qq号 id
		String wx =  obj_vars.optString("wx"); // wx号 id
		String nick_name =  obj_vars.optString("nick_name"); //第三方登录昵称
		String avatar =  obj_vars.optString("avatar"); //第三方登录头像
		String sex =  obj_vars.optString("sex"); //第三方登录性别
		String DriverID =  obj_vars.optString("DriverID"); // android推送
		String IOSDriverID =  obj_vars.optString("IOSDriverID"); // ios推送
		String phone =  obj_vars.optString("phone"); // 绑定的手机号
		String sms_id =  obj_vars.optString("sms_id"); // 验证码id
		String sms_code =  obj_vars.optString("sms_code"); // 验证码
		String real_name =  obj_vars.optString("real_name"); //真实姓名
		String card_id =  obj_vars.optString("card_id"); //身份证号
		String loc_lng =  obj_vars.optString("loc_lng"); //经度
		String loc_lat =  obj_vars.optString("loc_lat"); //纬度
		if(sqlMapper.public_dataifexist("p_sms", "sms_code= '"+sms_code+"'"+" and sms_id= "+sms_id+" and sms_phone= '"+phone+"'")) {
			String where= "";
			Map<String, Object> user= sqlMapper.selectOne("select uid,nick_name,avatar,sex from p_user where phone= '"+phone+"'");
			if(user!= null) {
				where= " uid= "+user.get("uid");
			}
			Map<String, String> map =  new HashMap<String, String>();
			map.put("phone", phone);
			if(!real_name.isEmpty()) {
				map.put("real_name", real_name);
			}
			if(!card_id.isEmpty()) {
				map.put("card_id", real_name);
			}
			if(user== null||user.get("nick_name")== null||user.get("nick_name").equals("")) {
				map.put("nick_name", nick_name);
			}
			if(user== null||user.get("avatar")== null||user.get("avatar").equals("")) {
				map.put("avatar", avatar);
			}
			if(user== null||user.get("sex")== null||user.get("sex").equals(0)) {
				map.put("sex", sex);
			}
			if(!qq.isEmpty()) {
				map.put("qq", qq);
			}
			if(!wx.isEmpty()) {
				map.put("wx", wx);
			}
			map.put("DriverID", DriverID);
			map.put("IOSDriverID", IOSDriverID);
			map.put("loc_lng", loc_lng);
			map.put("loc_lat", loc_lat);
			String token =  UUID.randomUUID().toString();
			map.put("token", token);
			int res =  sqlMapper.insert_or_update("p_user", map, where);
			if(res>0) {
				Map<String, Object> result =  sqlMapper.public_one_detail("p_user", new HashMap<String, String>() {
					{
						put("phone", phone);
						put("token", token);
					}
				});
				results.setResult(result);//输出：列表数据
				results.setMessage("绑定成功");
				results.setStatus(1);
			}else {
				results.setMessage("绑定失败");
				results.setStatus(0);
			}
		}else {
			results.setMessage("验证码输入有误");
			results.setStatus(0);
		}
	}
	// 接口功能：用户方个人详情修改
	public void personage_details_set() throws SQLException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String uid =  obj_vars.optString("uid"); //用户id
		String sex =  obj_vars.optString("sex"); //1-男 2-女
		String nick_name =  obj_vars.optString("nick_name"); //昵称
		String avatar =  obj_vars.optString("avatar"); //头像
		Map<String, String> map= new HashMap<>();
		if(!sex.isEmpty()) {
			map.put("sex", sex);
		}
		if(!nick_name.isEmpty()) {
			map.put("nick_name", nick_name);
		}
		if(!avatar.isEmpty()) {
			map.put("avatar", avatar);
		}
		int res= sqlMapper.insert_or_update("p_user",map, "uid= "+uid);
		if(res>0) {
			results.setStatus(1);//输出：状态1成功 0失败
			results.setMessage("修改成功");//输出：提示信息
		}else {
			results.setStatus(0);
			results.setMessage("修改失败");
		}

	}
	// 接口功能：用户端首页(ok)
	public void user_home_page_get() throws SQLException {
		Map<String, Object> result =  new HashMap<String, Object>();
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String city =  obj_vars.optString("city"); //城市
		String area =  obj_vars.optString("area"); // 首页定位区
		String address =  obj_vars.optString("address"); // 首页定位详细地址
		String loc_lng =  obj_vars.optString("loc_lng"); //经度
		String loc_lat =  obj_vars.optString("loc_lat"); //纬度
		String uid =  obj_vars.optString("uid"); //用户id
		Map<String,String> map1= new HashMap<String, String>();
		String cityid= "";//城市id
		String taskwhere = "";
		result.put("city_id", "");
		Map<String, Object> citymap= sqlMapper.selectOne("select id,spid from p_areas where ifshow= 1 and pid!= 0  and (name= '"+city+"' or alias= '"+city+"')");
		if(citymap!= null) {
			result.put("city_id", citymap.get("id").toString());//输出:定位城市id
		}
		if(!uid.isEmpty()) {
			if(!city.isEmpty()) {
				if(citymap!= null) {
					cityid= citymap.get("id").toString();
					result.put("city_id", cityid);//输出:定位城市id
				Map<String, Object> map=  sqlMapper.selectOne("select id,spid from p_areas where ifshow= 1 and pid= "+citymap.get("id")+" and LENGTH(spid) =  10 and (name= '"+area+"' or alias= '"+area+"')");
				if(map!= null) {
					map1.put("loc_city_id", citymap.get("id").toString());
					map1.put("loc_district_id", map.get("id").toString());
					map1.put("loc_address", address);
				}
				}
			}
			map1.put("loc_lng", loc_lng);
			map1.put("loc_lat", loc_lat);
			sqlMapper.insert_or_update("p_user",map1, "uid= "+uid);
		}
		if(!cityid.isEmpty()&&!cityid.equals("")) {
			taskwhere= " and b.city_id= "+cityid+" ";
		}
		//首页行业显示
		List<Map<String, Object>> list=   sqlMapper.public_list_column("catalog_id,cata_type,catalog_name,catalog_sketch,catalog_desc,catalog_img,top_img,parent_id,ifhome", "m_catalog", "  parent_id= 0 and ifhome= 1", "sortid");
		for (Map<String, Object> map : list) {
			List<Map<String, Object>> ch=   sqlMapper.public_list_column("catalog_id,cata_type,catalog_name,catalog_sketch,catalog_desc,catalog_img,top_img,parent_id,ifhome", "m_catalog", " parent_id= "+map.get("catalog_id") +" and ifhome= 1 limit 8", "");
			map.put("child", ch);
		}
		result.put("industry", list);//行业
		result.put("know_banner", get_setData(101,0));//了解我们
		result.put("top_banner", get_banner(100));//顶部banner图
		result.put("center_banner", get_banner(101));//中间banner图
		result.put("recommend_news", sqlMapper.selectList("select news_id,news_img,news_title from m_news"));//热门|推荐
		result.put("recommend_user", sqlMapper.selectList("SELECT b.pid,IFNULL(c.work_avatar,'') work_avatar,b.srv_title,b.srv_id,b.catalog_id,c.experience,d.catalog_name  from  m_task_recommend a,s_service b,s_provider c,m_catalog d where a.task_id= b.srv_id and d.catalog_id= b.catalog_id and  b.pid= c.pid and rec_type= 1 ORDER BY a.ordid"));//优质|服务
		result.put("task_list", sqlMapper.selectList("SELECT IFNULL(a.avatar,'') avatar,IFNULL(a.nick_name,'') nick_name,real_name,b.task_desc,b.task_id from p_user a,m_task b where a.uid= b.uid and b.status= 2 "+taskwhere+"ORDER BY b.create_time desc LIMIT 50"));//任务列表
		result.put("provider_list", sqlMapper.selectList("SELECT a.pid,b.srv_id,work_avatar,experience,CONCAT(left(real_name,1),'师傅') as real_name,c.catalog_name from s_provider a ,s_service b,m_catalog c where a.is_forbid= 0 and a.pid= b.pid and b.catalog_id= c.catalog_id ORDER BY a.create_time desc LIMIT 50"));//服务之星
		results.setResult(result);//输出：列表数据
		results.setStatus(1);//输出：状态1成功 0失败
		results.setMessage("ok");//输出：提示信息
	}

	// 接口功能：获取热门推荐内容
	public void hot_news_get() throws SQLException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String news_id =  obj_vars.optString("news_id"); //热门推荐id
		String html= sqlMapper.public_one_detail("IFNULL(news_content,'') news_content", "m_news", "news_id= "+news_id).get("news_content").toString();
		if(!html.equals("")) {
			html= htmlUtils.replace(html, filesave_path);
		}
		results.setResult(html);//输出：列表数据
		results.setStatus(1);//输出：状态1成功 0失败
		if(!html.trim().isEmpty()) {
			results.setMessage("ok");//输出：提示信息
		}else {
			results.setMessage("暂无数据");//输出：提示信息
		}
	}

	// 接口功能：分类:首页分类-更多  分类界面数据 分类选择数据(ok)
	public void catalog_list_get() throws SQLException {
		Map<String, Object> result =  new HashMap<String, Object>();
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String catalog_id =  obj_vars.optString("catalog_id"); //父级id-数据类型为2的时候不用传
		String CATA_TYPE =  obj_vars.optString("cata_type"); //分类：1普通分类(房屋卫士，贴心管家)；2专题分类(邻里和大学生)-数据类型为2的时候不用传
		String rec_type= obj_vars.optString("rec_type"); //推荐类型：1首页优质服务；2邻里推荐；3大学生推荐 没有时不传-数据类型为2的时候不用传
		String datatype= obj_vars.optString("datatype"); //数据类型 1-首页分类-更多 2-分类界面数据-必传 3-选择时用到的分类数据（其它参数都不用传）
		String sql= "catalog_id,cata_type,catalog_name,catalog_sketch,catalog_desc,catalog_img,top_img,parent_id,ifhome";
		String where= "";
		List<Map<String, Object>> resultone= new ArrayList<>();
		switch (datatype) {
			case "1":
				where= "parent_id=  " + catalog_id;
				resultone=   sqlMapper.public_list_column(sql, "m_catalog", where, "");
				if(CATA_TYPE.equals("2")) {
					for (Map<String, Object> map : resultone) {
						where= " parent_id= "+map.get("catalog_id");
						List<Map<String, Object>> ch=   sqlMapper.public_list_column(sql, "m_catalog", where, "");
						map.put("child", ch);
					}
					if(!rec_type.isEmpty()) {
						result.put("recommend_user", sqlMapper.selectList("select b.catalog_id,a.pid,a.work_avatar,b.srv_title,c.catalog_name,a.experience from s_provider a,s_service b,m_catalog c WHERE a.pid in (SELECT task_id from m_task_recommend WHERE rec_type= "+rec_type+") and a.pid= b.pid  and b.catalog_id= c.catalog_id"));//推荐
					}
				}
				result.put("catalog", resultone);
				result.put("topImg", sqlMapper.selectOne("select IFNULL(top_img,'') as top_img from m_catalog where catalog_id= "+catalog_id).get("top_img"));
				results.setResult(result);//输出：列表数据
				results.setStatus(1);//输出：状态1成功 0失败
				results.setMessage("ok");//输出：提示信息
				break;
			case "2":
				where= "cata_type= 1 and parent_id= 0";
				resultone=   sqlMapper.public_list_column(sql, "m_catalog", where, "");
				for (Map<String, Object> map : resultone) {
					where= " cata_type= 1 and parent_id= "+map.get("catalog_id");
					List<Map<String, Object>> ch=   sqlMapper.public_list_column(sql, "m_catalog",where, "sortid");
					map.put("child", ch);
				}
				results.setResult(resultone);
				results.setStatus(1);
				results.setMessage("ok");
				break;
			case "3":
				sql= "catalog_id,catalog_name,cata_type";
				resultone=   sqlMapper.public_list_column(sql, "m_catalog", "PARENT_ID= 0", "sortid");
				for (Map<String, Object> map : resultone) {
					where= "parent_id= "+map.get("catalog_id");
					List<Map<String, Object>> ch=   sqlMapper.public_list_column(sql, "m_catalog",where, "");
					if(Integer.parseInt(map.get("cata_type").toString())== 1) {
						map.put("child", ch);
					}else {
						List<Map<String, Object>> sumlist= new ArrayList<>();
						for (Map<String, Object> map2 : ch) {
							where= "parent_id= "+map2.get("catalog_id");
							List<Map<String, Object>> sum= sqlMapper.public_list_column(sql, "m_catalog",where, "");
							for (Map<String, Object> map3 : sum) {
								sumlist.add(map3);
							}
						}
						map.put("child",sumlist);
					}
				}
				results.setResult(resultone);
				results.setStatus(1);
				results.setMessage("ok");
				break;
		}
		if(resultone.isEmpty()) {
			results.setStatus(1);
			results.setMessage("暂无数据！");
		}
	}

	// 接口功能：服务商-地图信息(ok)
	public void provider_map_list_get() throws SQLException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String catalog_id= obj_vars.optString("catalog_id"); // 分类id
		String loc_lng =  obj_vars.optString("loc_lng"); //经度
		String loc_lat =  obj_vars.optString("loc_lat"); //纬度
		String where= "(select pid from s_service where catalog_id= "+catalog_id+")";
		List<Map<String, Object>> resultone= new ArrayList<>();
		resultone= sqlMapper.selectList("SELECT * from (SELECT s_provider.pid,loc_lng,loc_lat,ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(("+loc_lat+" * PI() / 180 - loc_lat * PI() / 180) / 2),2) + COS("+loc_lat+"  * PI() / 180) * COS(loc_lat * PI() / 180) * POW(SIN(("+loc_lng+" * PI() / 180 - loc_lng * PI() / 180) / 2),2))) * 1000) AS juli from s_provider WHERE is_forbid= 0 and s_provider.pid in (select pid from s_service where catalog_id= "+catalog_id+")) as a WHERE juli<20000", null);
		results.setResult(resultone);//输出：列表数据
		results.setStatus(1);//输出：状态1成功 0失败
		results.setMessage("ok");//输出：提示信息
		if(resultone.isEmpty()) {
			results.setStatus(1);
			results.setMessage("暂无数据！");
		}
	}

	// 接口功能：服务商-列表数据(ok)
	public void provider_list_get() throws SQLException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String catalog_id= obj_vars.optString("catalog_id"); // 分类id
		int pagenum= obj_vars.optInt("pagenum"); //第几页
		String key= obj_vars.optString("key"); //关键搜索 (数据格式[{\"key\":\"sex\",\"value\":\"男\"},{\"key\":\"loc_city_id\",\"value\":\"武汉市\"}])
		String loc_lng =  obj_vars.optString("loc_lng"); //用户经度
		String loc_lat =  obj_vars.optString("loc_lat"); //用户纬度
		String loc_city_id =  obj_vars.optString("loc_city_id"); //城市id
		String orderby =  obj_vars.optString("orderby"); //排序
		String keyword =  obj_vars.optString("keyword"); //关键字搜索
		String where= "";
		String order_by= "srv_num";
		List<Map<String, Object>> resultone= new ArrayList<>();
		if(!loc_city_id.isEmpty()) {
			where+= " and a.loc_city_id= "+loc_city_id;
		}
//				 if(!sex.isEmpty()) {
//					 where+= " and sex= "+sex;
//				 }
//				 if(!age.isEmpty()) {
//					 where+= " and DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(birthday)), '%Y')+0 between "+age.split(",")[0]+" and "+age.split(",")[1];
//				 }
//				 if(!education.isEmpty()) {
//					 where+= " and education= "+education;
//				 }
//				 if(!ifservice.isEmpty()) {
//					 if(ifservice.equals("有培训")) {
//						 where+= " and train_num>0";
//					 }
//					 if(ifservice.equals("无培训")) {
//						  where+= " and train_num= 0";
//					 }
//				 }
//				 key =  key.substring(1, key.length() - 1);
		if(!key.isEmpty()) {
			JSONArray remarkjsonayy =  JSONArray.fromObject(key);
			if (remarkjsonayy.size() > 0) {
				for (int i =  0; i < remarkjsonayy.size(); i++) {
					JSONObject files =  remarkjsonayy.getJSONObject(i);
					String name =  files.getString("key");
					String value =  files.getString("value");
					if(name.equals("sex")) {
						if(value.equals("男")) {
							value= "1";
						}else if(value.equals("女")) {
							value= "2";
						}
						where+= " and "+name+" =  "+value;
					}
					if(name.equals("age")) {
						where+= " and DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(birthday)), '%Y')+0 between "+value.split("-")[0]+" and "+value.split("-")[1];
					}
					if(name.equals("education")) {
						where+= " and "+name+" =  '"+value+"'";
					}
				}
			}
		}
		if(!orderby.isEmpty()) {
			if(orderby.equals("服务量从高到低")) {
				order_by= " srv_num desc ";
			}
			if(orderby.equals("服务量从低到高")) {
				order_by= " srv_num ";
			}
			if(orderby.equals("离我最近")) {
				order_by= " ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(("+loc_lat+" * PI() / 180 - loc_lat * PI() / 180) / 2),2) + COS("+loc_lat+"  * PI() / 180) * COS(loc_lat * PI() / 180) * POW(SIN(("+loc_lng+" * PI() / 180 - loc_lng * PI() / 180) / 2),2))) * 1000)";
			}
		}
		String juli= "";
		if(loc_lat.equals("0")&&loc_lng.equals("0")||loc_lng.isEmpty()||loc_lat.isEmpty()) {
			juli= " '未知' as juli,";
		}else {
			juli= " ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(("+loc_lat+" * PI() / 180 - loc_lat * PI() / 180) / 2),2) + COS("+loc_lat+"  * PI() / 180) * COS(loc_lat * PI() / 180) * POW(SIN(("+loc_lng+" * PI() / 180 - loc_lng * PI() / 180) / 2),2))) * 1000) AS juli,";
		}
		if(!keyword.isEmpty()) {
			where+= " and (b.catalog_id in (select catalog_id from m_catalog where catalog_name like '%"+keyword+"%') ";
			where+= " or a.real_name like '%"+keyword+"%' ";
			where+= " or b.srv_title like '%"+keyword+"%' )";
		}
		if(!catalog_id.isEmpty()) {
			where+= " and b.catalog_id= "+catalog_id;
		}
		resultone=  sqlMapper.public_list_page(juli+"a.pid,work_avatar,srv_title,real_name,DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(birthday)), '%Y')+0 AS age,nativeplace,b.srv_time,srv_num,a.evl_level,loc_lng,loc_lat,IFNULL(c.name,'') as cityname,b.catalog_id", "s_provider a LEFT JOIN p_areas c ON a.loc_city_id= c.id,s_service b ", "is_forbid= 0 and a.pid= b.pid "+where, order_by,pagenum);
		results.setResult(resultone);
		results.setStatus(1);
		results.setMessage("ok");
		if(resultone.isEmpty()) {
			results.setStatus(1);
			results.setMessage("暂无数据！");
		}
	}
	// 接口功能：服务商-列表-配置数据(ok)
	public void provider_configuration_list_get() throws SQLException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String city= obj_vars.optString("city");// 城市
		String datatype= obj_vars.optString("datatype");// 1-服务商-列表-配置数据 2-城市
		String where= "";
		List<Map<String, Object>> labalList= new ArrayList<>();
		Map<String, Object> result= new HashMap<>();
		Map<String, Object> cityList= new HashMap<>();
		cityList.put("key","city_name");
		cityList.put("title","城市");
		List<Map<String, Object>> citys= new ArrayList<>();
		if(!city.isEmpty()) {
			Map<String, Object> topcity= sqlMapper.selectOne("select alias,id from p_areas where alias= '"+city+"' or name= '"+city+"'");
			if(topcity!= null) {
				citys.add(topcity);

			}
		}
		List<Map<String, Object>> data= sqlMapper.public_list_column("alias,id", "p_areas", " ifshow= 1 and  LENGTH(spid) =  5 and alias!= '"+city+"' and name!= '"+city+"'", "");
		for (Map<String, Object> map : data) {
			citys.add(map);
		}
//					 List<String> list= new ArrayList<>();
//					 for (Map<String, Object> map : citys) {
//						 list.add(map.get("alias").toString());
//					}
		cityList.put("data", citys);
		if(datatype.equals("1")) {
			//
			List<String> labalList1= new ArrayList<>();
			Map<String, Object> list1= new HashMap<>();

			labalList1.add("男");
			labalList1.add("女");
			list1.put("key", "sex");
			list1.put("title", "性别");
			list1.put("data", labalList1);
			//
			List<String> labalList2= new ArrayList<>();
			Map<String, Object> list4= new HashMap<>();


			list4.put("key", "age");
			list4.put("title", "年龄");
			labalList2.add("18-25");
			labalList2.add("25-35");
			labalList2.add("35-45");
			labalList2.add("45-60");
			list4.put("data", labalList2);

//
			List<String> labalList3= new ArrayList<>();
			Map<String, Object> list5= new HashMap<>();


			list5.put("key", "education");
			list5.put("title", "学历");
			labalList3.add("高中");
			labalList3.add("大专");
			labalList3.add("本科");
			labalList3.add("硕士及以上");
			list5.put("data", labalList3);
//
			List<String> labalList4= new ArrayList<>();
			Map<String, Object> list6= new HashMap<>();


			list6.put("key", "ifservice");
			list6.put("title", "是否培训");
			labalList4.add("有培训");
			labalList4.add("无培训");
			list6.put("data", labalList4);


			labalList.add(list1);
			labalList.add(list4);
			labalList.add(list5);
			labalList.add(list6);

			//
			List<String> labalList5= new ArrayList<>();
			Map<String, Object> list7= new HashMap<>();
			labalList5.add("服务量从高到低");
			labalList5.add("服务量从低到高");
			labalList5.add("离我最近");
			list7.put("key", "orderby");
			list7.put("title", "综合排序");
			list7.put("data", labalList5);
			result.put("cityList", cityList);
			result.put("labalList", labalList);
			result.put("orderbyList", list7);
		}else if(datatype.equals("2")){
			result.put("cityList", citys);
		}
		results.setResult(result);
		results.setStatus(1);
		results.setMessage("ok");
		if(result.isEmpty()) {
			results.setStatus(1);
			results.setMessage("暂无数据！");
		}
	}
	// 接口功能：服务商-详情 数据类型1-列表详情 2-服务之星(ok) 3-地图服务商详情 4-评价
	public void provider_detail_get() throws SQLException {
		Map<String, Object> result =  new HashMap<String, Object>();
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String pid= obj_vars.optString("pid"); // 服务商id
		String uid= obj_vars.optString("uid"); //用户id-用来判断是否收藏 数据类型为1时传
		String catalog_id= obj_vars.optString("catalog_id"); //分类id 数据类型为 2时不传
		String datatype= obj_vars.optString("datatype"); //数据类型1-列表详情 2-服务之星 3-地图详情 4-评价（用户评价服务商时服务商的详情）
		String srv_id= obj_vars.optString("srv_id"); //服务id 数据类型为1，3不传  数据类型为4时只用传改字段
		switch (datatype) {
			case "1":
				Map<String, Object> provider =  sqlMapper.public_one_detail("work_no,real_name,sex,phone,DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(birthday)), '%Y')+0 AS age,nativeplace,education,work_year,certificate,train_num,loc_lng,loc_lat,loc_city_id","S_PROVIDER ","pid= "+pid);
				Map<String, Object> cityname = sqlMapper.selectOne("select name from p_areas where id= "+provider.get("loc_city_id"));
				if(cityname!= null) {
					provider.put("cityname", cityname.get("name"));
				}else {
					provider.put("cityname", "未知");
				}
				String realphone= provider.get("phone").toString();
				provider.put("phone", basictool.string_star(realphone, 3, 7));
				result.put("provider_basic_date", provider);
				provider= sqlMapper.public_one_detail("srv_id,srv_img,srv_num,srv_title,srv_time,a.evl_level,evl_num,catalog_name","s_service a,m_catalog b","a.catalog_id= b.catalog_id and a.catalog_id= "+catalog_id+" and pid= "+pid);
				result.put("server_detail", provider);
				result.put("server_content",sqlMapper.public_list_column("part_type,part_data,IFNULL(height,'') height,IFNULL(width,'') width", "s_service_detail", "srv_id= "+provider.get("srv_id").toString(), "ordid "));
				if(!uid.isEmpty()) {
					Map<String, Object> point= sqlMapper.public_one_detail("m_point","uid= "+uid+" and is_trans= 0 and status= 2 and srv_id= "+provider.get("srv_id"));
					if(point!= null) {
						if(point.get("is_trans").equals(0)) {
							provider.put("realphone",realphone);
							provider.put("ifaffirm", true);
							provider.put("point_id",point.get("point_id"));
						}else {
							provider.put("ifaffirm", false);
							provider.put("point_id", "");
						}
					}else {
						provider.put("ifaffirm", false);
						provider.put("point_id", "");
					}
					provider.put("ifcollect", sqlMapper.public_dataifexist("m_collect","uid= "+uid+" and srv_id= "+provider.get("srv_id"))) ;
				}else {
					provider.put("point_id","");
					provider.put("ifaffirm",false);
					provider.put("ifcollect",false);
				}
				break;
			case "2":
				result = sqlMapper.public_one_detail("a.phone,a.pid,b.srv_id,work_avatar,experience,CONCAT(left(real_name,1),'师傅') as real_name,c.catalog_name,TIMESTAMPDIFF(MINUTE,a.create_time,NOW()) as time","s_provider a ,s_service b,m_catalog c","a.is_forbid= 0 and a.pid= b.pid and b.catalog_id= c.catalog_id and a.pid= "+pid+" and b.srv_id= "+srv_id);
				result.put("phone", basictool.string_star(result.get("phone").toString(), 3, 7));
				if(Integer.parseInt(result.get("time").toString())/60>0) {
					result.put("time",Integer.parseInt(result.get("time").toString())/60+"小时");
				}else if(Integer.parseInt(result.get("time").toString())/720>0) {
					result.put("time",Integer.parseInt(result.get("time").toString())/60+"天");
				}
				break;
			case "3":
				result = sqlMapper.public_one_detail("pid,work_no,evl_level,real_name,sex,phone,DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(birthday)), '%Y')+0 AS age,nativeplace,education,work_year,certificate,train_num,loc_lng,loc_lat","s_provider","pid= "+pid);
				result.put("phone", basictool.string_star(result.get("phone").toString(), 3, 7));
				Map<String, Object> server = sqlMapper.public_one_detail("GROUP_CONCAT(b.catalog_name) as catalog_name","s_service a,m_catalog b","a.catalog_id= b.catalog_id and pid= "+pid+" and b.catalog_id= "+catalog_id);
				result.put("catalog_name",server.get("catalog_name"));
				result.put("srv_id",sqlMapper.public_one_detail("srv_id", "s_service", "pid= "+pid+" and catalog_id= "+catalog_id).get("srv_id"));
				break;
			case "4":
				result = sqlMapper.public_one_detail("a.pid,c.catalog_name,b.real_name,work_avatar,b.evl_level,a.srv_num,IFNULL(p.name,'') as cityname,b.phone","s_service a ,s_provider b left join p_areas p on p.id= b.LOC_CITY_ID,m_catalog c","a.pid= b.pid and a.catalog_id= c.catalog_id and  a.srv_id= "+srv_id);
				break;
		}
		if(result.isEmpty()) {
			results.setStatus(1);
			results.setMessage("暂无数据！");
		}else {
			results.setResult(result);//输出：列表数据
			results.setStatus(1);//输出：状态1成功 0失败
			results.setMessage("ok");//输出：提示信息
		}
	}

	// 接口功能：用户即时点单
	public void user_point_set() throws SQLException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String uid= obj_vars.optString("uid"); //用户id
		String srv_id= obj_vars.optString("srv_id"); //服务id
		int res=  sqlMapper.insert_or_update("m_point", new HashMap<String, String>() {
			{
				put("uid", uid);
				put("srv_id",srv_id);
			}
		}, "");
		if(res>0) {
			Map<String, Object> result= new HashMap<>();
			result.put("point_id", res);
			results.setResult(result);//输出:点单id
			results.setStatus(1);
			results.setMessage("点单成功");
		}else {
			results.setStatus(0);//输出：提示信息
			results.setMessage("接口调用出错");//输出：提示信息
		}
	}
	// 接口功能：用户发布任务
	public void user_task_set() throws SQLException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String uid= obj_vars.optString("uid"); //用户id
		String task_img= obj_vars.optString("task_img"); //任务图片多个用,隔开
		String task_title= obj_vars.optString("task_title"); //任务标题
		String task_desc= obj_vars.optString("task_desc"); //任务描述
		String catalog_id= obj_vars.optString("catalog_id"); //分类id
		String contact_name= obj_vars.optString("contact_name"); //联系人
		String price= obj_vars.optString("price"); //价格：0表示面议
		String contact_phone= obj_vars.optString("contact_phone"); //联系电话
		String srv_time= obj_vars.optString("srv_time"); //服务时间
		String area= obj_vars.optString("area"); //服务地区
		String city= obj_vars.optString("city"); //服务城市
		String srv_address= obj_vars.optString("srv_address"); //服务详细地址
		String lng= obj_vars.optString("lng"); //经度
		String lat= obj_vars.optString("lat"); //纬度
		Map<String, Object> result= new HashMap<>();
		Map<String, Object> citymap= sqlMapper.selectOne("select id,spid from p_areas where ifshow= 1 and pid!= 0  and (name= '"+city+"' or alias= '"+city+"')");
		if(citymap!= null) {
		Map<String, Object> map=  sqlMapper.selectOne("select id,spid from p_areas where ifshow= 1 and pid= "+citymap.get("id")+" and LENGTH(spid) =  10 and (name= '"+area+"' or alias= '"+area+"')");
		if(map!= null) {
		String district_id= map.get("id").toString();
			String city_id= (map.get("spid").toString()).split("\\|")[1];
			int res=  sqlMapper.insert_or_update("m_task", new HashMap<String, String>() {
				{
					put("uid", uid);
					put("task_title",task_title);
					put("task_desc", task_desc);
					put("catalog_id", catalog_id);
					put("contact_name", contact_name);
					put("price", price);
					put("contact_phone", contact_phone);
					put("srv_time", srv_time);
					put("district_id", district_id);
					put("city_id", city_id);
					put("srv_address", srv_address);
					put("lng", lng);
					put("lat", lat);
				}
			}, "");
			if(res>0) {
				if(!task_img.isEmpty()) {
					String img[]= task_img.split(",");
					for (int i =  0; i < img.length; i++) {
						set_content(2, img[i], 100, res, i);
					}
				}
				result.put("task_id", res);
				results.setResult(result);//输出:任务id
				results.setStatus(1);//输出：状态1成功 0失败
				results.setMessage("保存成功");//输出：提示信息
			}else {
				results.setStatus(0);
				results.setMessage("接口调用出错");
			}}else {
				results.setStatus(0);
				results.setMessage("该地区暂未开放！");
			}
		}else {
			results.setStatus(0);
			results.setMessage("该地区暂未开放！");
		}
	}
	// 接口功能：消息列表 1-用户方2-服务商
	public void user_message_list_get() throws SQLException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String role= obj_vars.optString("role"); //1-用户方2-服务商
		String userid= obj_vars.optString("userid"); //1-用户id 2-服务商id
		int pagenum= obj_vars.optInt("pagenum"); //第几页
		String datatype= obj_vars.optString("datatype"); //1-平台消息 2-服务消息
		String sql= "msg_id,msg_type,msg_type_id,msg_title,msg_content,date_format(create_time,'%Y-%m-%d %h:%i:%s') create_time";
		List<Map<String, Object>> messagelist= new ArrayList<>();
		int msg_type= 0;
		switch (role) {
			case "1":
				msg_type= 100;
				break;

			case "2":
				msg_type= 200;
				break;
		}
		switch (datatype) {
			case "1":
				messagelist=  sqlMapper.public_list_page(sql,"p_message","msg_type= "+msg_type,"create_time desc",pagenum);
				break;
			case "2":
				messagelist=  sqlMapper.public_list_page(sql,"p_message","role= "+role+" and user_id= "+userid,"create_time desc",pagenum);
				break;
		}

		if(!messagelist.isEmpty()) {
			results.setResult(messagelist);
			results.setMessage("OK");
		}else {
			results.setMessage("暂无数据");//输出：提示信息
		}
		results.setStatus(1);//输出：状态1成功 0失败
	}
	// 接口功能：我的打赏 1-用户方2-服务商
	public void user_money_list_get() throws SQLException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String datatype= obj_vars.optString("datatype"); //1-用户方2-服务商
		String userid= obj_vars.optString("userid"); //1-用户id 2-服务商id
		int pagenum= obj_vars.optInt("pagenum"); //第几页
		Map<String, Object> resultmap= new HashMap<>();
		List<Map<String, Object>> moneylist=  sqlMapper.public_list_page("IFNULL(b.catalog_name,'') catalog_name,reward_id,reward_type,business_id,amount,date_format(pay_time,'%Y-%m-%d %h:%i:%s') pay_time","p_reward a left join m_catalog b on a.catalog_id= b.catalog_id","user_type= "+datatype+" and status= 2 and user_id= "+userid,"pay_time desc",pagenum);
		Map<String, Object> moneySum=  new HashMap<>();
		switch (datatype) {
		case "1":
			moneySum= sqlMapper.public_one_detail("reward_amount amount", "p_user", "uid= "+userid);
			break;

		case "2":
			moneySum= sqlMapper.public_one_detail("reward_amount amount", "s_provider", "pid= "+userid);
			break;
		}
		resultmap.put("moneylist", moneylist);
		if(moneySum!= null) {
			resultmap.put("moneySum", moneySum.get("amount"));
		}else {
			resultmap.put("moneySum", 0);
		}
		if(moneylist.size()>0) {
			results.setResult(resultmap);
			results.setMessage("OK");
		}else {
			results.setMessage("暂无数据");//输出：提示信息
			results.setResult(resultmap);
		}
		results.setStatus(1);//输出：状态1成功 0失败
	}
	// 接口功能：收藏 1-用户方2-服务商
	public void user_mycollect_set() throws SQLException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String datatype= obj_vars.optString("datatype"); //1-用户方2-服务商
		String userid= obj_vars.optString("userid"); //1-用户id 2-服务商id
		String objectid= obj_vars.optString("objectid"); //1-用户方收藏的SRV_ID 2-服务方收藏的TASK_ID
		boolean flag= false;
		int res= 0;
		switch (datatype) {
			case "1":
				flag=  sqlMapper.public_dataifexist("m_collect","uid= "+userid+" and srv_id= "+objectid);
				if(flag) {
					res= sqlMapper.delete("delete from m_collect where uid= "+userid+" and srv_id= "+objectid);
				}else {
					res=  sqlMapper.insert_or_update("m_collect", new HashMap<String, String>() {
						{
							put("uid", userid);
							put("srv_id",objectid);
						}
					}, "");
				}
				break;
			case "2":
				flag=  sqlMapper.public_dataifexist("s_collect","pid= "+userid+" and task_id= "+objectid);
				if(flag) {
					res= sqlMapper.delete("delete from s_collect where pid= "+userid+" and task_id= "+objectid);
				}else {
					res=  sqlMapper.insert_or_update("s_collect", new HashMap<String, String>() {
						{
							put("pid", userid);
							put("task_id",objectid);
						}
					}, "");
				}
				break;
		}
		if(res>0) {

			if(flag) {
				results.setMessage("取消收藏成功");
			}else {
				results.setMessage("收藏成功");
			}
			results.setStatus(1);
		}else {

			results.setMessage("操作失败");//输出：提示信息
			results.setStatus(0);//输出：状态1成功 0失败
		}

	}
	// 接口功能：我的收藏 1-用户方2-服务商
	public void user_mycollect_list_get() throws SQLException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String datatype= obj_vars.optString("datatype"); //1-用户方2-服务商
		String userid= obj_vars.optString("userid"); //1-用户id 2-服务商id
		String loc_lng =  obj_vars.optString("loc_lng"); //用户经度
		String loc_lat =  obj_vars.optString("loc_lat"); //用户纬度
		int pagenum= obj_vars.optInt("pagenum"); //第几页
		List<Map<String, Object>> result= new ArrayList<>();
		String juli= "";
		if(loc_lat.equals("0")&&loc_lng.equals("0")||loc_lng.isEmpty()||loc_lat.isEmpty()) {
			juli= " '未知' as juli,";
		}else {
			juli= "ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(("+loc_lat+" * PI() / 180 - loc_lat * PI() / 180) / 2),2) + COS("+loc_lat+"  * PI() / 180) * COS(loc_lat * PI() / 180) * POW(SIN(("+loc_lng+" * PI() / 180 - loc_lng * PI() / 180) / 2),2))) * 1000) AS juli,";
		}
		switch (datatype) {
			case "1":
				result= sqlMapper.public_list_page(juli+"a.pid,work_avatar,srv_title,real_name,DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(birthday)), '%Y')+0 AS age,nativeplace,b.srv_time,srv_num,a.evl_level,loc_lng,loc_lat,b.catalog_id,loc_city_id,IFNULL(d.`name`,'未知') cityname", "s_provider a LEFT JOIN p_areas d ON a.loc_city_id= d.id,s_service b,M_COLLECT c", "is_forbid= 0 and a.pid= b.pid  and c.srv_id= b.srv_id and c.uid= "+userid, "c.create_time DESC",pagenum);
//					 		for (Map<String, Object> map : result) {
//					 			map.put("cityname", sqlMapper.selectOne("select name from p_areas where id= "+map.get("loc_city_id")).get("name"));
//							}
				break;
			case "2":
				List<Map<String, Object>> data= sqlMapper.public_list_page(juli+"a.task_id,IFNULL(b.nick_name,'某某用户') nick_name,b.real_name,b.evl_level,a.task_desc,c.catalog_name,date_format(a.create_time,'%Y-%m-%d %H:%i:%s') as create_time,a.district_id", "m_task a,s_collect e,p_user b ,m_catalog c", "a.uid= b.uid and c.catalog_id= a.catalog_id and e.task_id= a.task_id and e.pid= "+userid, "a.create_time desc", pagenum);
				for (Map<String, Object> map : data) {
					map.put("cityname", getAreaDetailById(map.get("district_id").toString()).get("city"));
					result.add(map);
				}
				break;
		}
		if(!result.isEmpty()) {
			results.setResult(result);//输出：列表数据
			results.setMessage("OK");
		}else {
			results.setMessage("暂无数据");//输出：提示信息
		}
		results.setStatus(1);//输出：状态1成功 0失败
	}
	// 接口功能：用户-我的发布
	public void user_myissue_list_get() throws SQLException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String uid= obj_vars.optString("uid"); //用户id
		int pagenum= obj_vars.optInt("pagenum"); //第几页
		int ifdetele= 0;
		List<Map<String, Object>> result= sqlMapper.public_list_page("task_id,task_title,task_desc,catalog_name,is_trans,date_format(a.create_time,'%Y-%m-%d %H:%i:%s') as create_time", "m_task a,m_catalog b", "a.catalog_id= b.catalog_id and status= 2 and uid= "+uid, "a.create_time desc", pagenum);
		List<Map<String, Object>> result1= new ArrayList<>();
		if(!result.isEmpty()) {
			for (Map<String, Object> map : result) {
				if(sqlMapper.public_dataifexist("m_order", "status!= '已完成' and task_id= "+map.get("task_id"))) {
					ifdetele= 1;
				}
				map.put("ifdetele", ifdetele);
				result1.add(map);
			}
			results.setResult(result1); //输出：列表数据 is_trans 0-未抢单 1-已抢单 ifdetele 0-可删1-不可删
			results.setMessage("OK"); //输出：提示信息
		}else {
			results.setMessage("暂无数据");
		}
		results.setStatus(1); //输出：状态1成功 0失败
	}
	// 接口功能：用户-我的订单
	public void user_myorder_list_get() throws SQLException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String uid= obj_vars.optString("uid"); //用户id
		int pagenum= obj_vars.optInt("pagenum"); //第几页
		String status= obj_vars.optString("status"); //状态传文字 待确认，进行中，已完成
		List<Map<String, Object>> result= new ArrayList<>();
//						 result= sqlMapper.public_list_page("b.oid,e.catalog_name,a.real_name,d.srv_title", "s_provider a,m_order b,m_task c,s_service d,m_catalog e", "c.catalog_id= d.catalog_id and a.pid= d.pid and b.pid= a.pid and c.task_id= b.task_id and c.catalog_id= e.catalog_id and b.uid= "+uid+" and b.status= "+"'"+status+"' and history_type IS NULL", "b.create_time desc", pagenum);
		result= sqlMapper.public_list_page("b.srv_id,b.oid,b.task_id,b.point_id,history_type,e.catalog_name,a.real_name,d.srv_title,a.work_avatar,b.status,IFNULL(t.task_title,'') task_title", "s_provider a,m_order b left join m_task t on t.task_id= b.task_id,s_service d,m_catalog e", "a.pid= d.pid and b.pid= a.pid and d.srv_id= b.srv_id and d.catalog_id= e.catalog_id and b.uid= "+uid+" and b.status= "+"'"+status+"' and IFNULL(b.history_type,'')!= 2", "b.create_time desc", pagenum);
		if(!result.isEmpty()) {
			results.setResult(result);//输出：列表数据 is_trans 0-未抢单 1-已抢单
			results.setMessage("OK");//输出：提示信息
		}else {
			results.setMessage("暂无数据");
		}
		results.setStatus(1);//输出：状态1成功 0失败
	}
	// 接口功能：用户-我的订单-操作
	public void user_myorder_operation_set() throws SQLException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String uid= obj_vars.optString("uid"); //用户id
		String oid= obj_vars.optString("oid"); //订单id
		String taskid= obj_vars.optString("taskid"); //任务id(任务id和点单id二传一 )
		String point_id= obj_vars.optString("point_id"); //点单id(任务id和点单id二传一 )
		String buttontype= obj_vars.optString("buttontype"); //操作按钮1-同意 2-拒绝 3-确认完成 4-删除
		String srv_id= obj_vars.optString("srv_id"); //服务id 3-确认完成的时候传
		int res= 0;
		Systemmessage systemmessage= new Systemmessage();
		switch (buttontype) {
			case "1":
				res=  sqlMapper.insert_or_update("m_order", new HashMap<String, String>() {
					{
						put("status","进行中");
					}
				}, "oid= "+oid+" and uid= "+uid);
				systemmessage.setMsg_type_id(Integer.parseInt(oid));
				systemmessage.setMsg_type(201);
				systemmessage.setRole(2);
				systemmessage.setUser_id(Integer.parseInt(sqlMapper.selectOne("select pid from m_order where oid= "+oid).get("pid").toString()));
				systemmessage.setMsg_title("服务消息");
				systemmessage.setMsg_content("恭喜！"+sqlMapper.selectOne("select CONCAT(left(real_name,1),'师傅') as real_name from p_user where uid= "+uid).get("real_name")+"已同意您的服务邀请");

				res= public_wx_systemmessage_set(systemmessage);
				break;
			case "2":
				res=  sqlMapper.insert_or_update("m_order", new HashMap<String, String>() {
					{
						put("status","已拒绝");
						put("is_history","1");
						put("history_type","1");
					}
				}, "oid= "+oid+" and uid= "+uid);
				if(res>0) {
					res=  sqlMapper.insert_or_update("m_task", new HashMap<String, String>() {
						{
							put("is_trans","0");
						}
					}, "task_id= "+taskid+" and uid= "+uid);
				}
				systemmessage.setMsg_type_id(Integer.parseInt(oid));
				systemmessage.setMsg_type(202);
				systemmessage.setRole(2);
				systemmessage.setUser_id(Integer.parseInt(sqlMapper.selectOne("select pid from m_order where oid= "+oid).get("pid").toString()));
				systemmessage.setMsg_title("服务消息");
				systemmessage.setMsg_content("抱歉，"+sqlMapper.selectOne("select CONCAT(left(real_name,1),'师傅') as real_name from p_user where uid= "+uid).get("real_name")+"已拒绝您的服务邀请");
				res= public_wx_systemmessage_set(systemmessage);
				break;
			case "3":
				res=  sqlMapper.insert_or_update("m_order", new HashMap<String, String>() {
					{
						put("status","已完成");
						put("finishtime",sqlMapper.public_getcurrenttime());
					}
				}, "oid= "+oid+" and uid= "+uid);
				systemmessage.setMsg_type_id(Integer.parseInt(oid));
				systemmessage.setMsg_type(204);
				systemmessage.setRole(2);
				systemmessage.setUser_id(Integer.parseInt(sqlMapper.selectOne("select pid from m_order where oid= "+oid).get("pid").toString()));
				systemmessage.setMsg_title("服务消息");
				systemmessage.setMsg_content(sqlMapper.selectOne("select CONCAT(left(real_name,1),'师傅') as real_name from p_user where uid= "+uid).get("real_name")+"已确认完成了订单");
				res= public_wx_systemmessage_set(systemmessage);
				/*res= provider(Integer.parseInt(srv_id),Integer.parseInt(oid));*/
				break;
			case "4":
				res=  sqlMapper.insert_or_update("m_order", new HashMap<String, String>() {
					{
						put("is_history","1");
						put("history_type","2");
					}
				}, "oid= "+oid+" and uid= "+uid);
				break;
		}
		if(res>0) {
			results.setMessage("操作成功");//输出：提示信息
			results.setStatus(1);//输出：状态1成功 0失败
		}else {
			results.setMessage("操作失败");
			results.setStatus(0);
		}
	}
	// 接口功能：用户端-订单-详情
	public void user_myorder_details_get() throws SQLException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String oid= obj_vars.optString("oid"); //订单id
		String task_id= obj_vars.optString("task_id"); //任务id(任务id和点单id二传一 )
		String point_id= obj_vars.optString("point_id"); //点单id(任务id和点单id二传一 )
		String srv_id= obj_vars.optString("srv_id"); //服务id
		Map<String, Object> map= new HashMap<>();
		Map<String, Object> map1=  sqlMapper.public_one_detail("a.oid,a.uid,a.status,a.order_no,date_format(a.create_time,'%Y-%m-%d %H:%i:%s') as jd_time,IFNULL(t.task_title,'') task_title,IFNULL(t.create_time,'') xd_time,IFNULL(a.finishtime,'') wc_time,IFNULL(p.create_time,'') dd_time", "m_order a left join m_task t on t.task_id= a.task_id left join m_point p on p.point_id= a.point_id", "oid= "+oid);
		Map<String, Object> map2=  sqlMapper.public_one_detail("srv_id,b.real_name,work_avatar,c.catalog_name,a.srv_title", "s_service a,s_provider b,m_catalog c", "a.pid= b.pid and c.catalog_id= a.catalog_id and a.srv_id= "+srv_id);
		if(!task_id.isEmpty()&&!task_id.equals("0")) {
			Map<String, Object> map3=  sqlMapper.selectOne("SELECT contact_name,contact_phone,district_id,srv_address from m_task a  where task_id= "+task_id);
			map.put("contact_name", map3.get("contact_name"));
			map.put("contact_phone", map3.get("contact_phone"));
			Map<String, String> address= getAreaDetailById(map3.get("district_id").toString());
			map.put("srv_address", address.get("province")+address.get("city")+address.get("area")+map3.get("srv_address").toString());
		}
		Map<String, Object> map4= sqlMapper.selectOne("select avatar,real_name,nick_name,phone,IFNULL(loc_city_id,'') loc_city_id,IFNULL(loc_address,'') loc_address from p_user where uid= "+map1.get("uid"));
		if(!point_id.isEmpty()&&!point_id.equals("0")) {
			if(!map4.get("loc_address").equals("")) {
//				Map<String, String> citymap= getAreaDetailById(map4.get("loc_city_id").toString());
				map.put("srv_address", map4.get("loc_address"));
			}else {
				map.put("srv_address", "线下与师傅沟通");
			}
			map.put("contact_name", map4.get("real_name"));
			map.put("nick_name", map4.get("nick_name"));
			map.put("contact_phone", map4.get("phone"));
		}
		map.put("status", map1.get("status"));
		map.put("task_title", map1.get("task_title"));
		map.put("order_no", map1.get("order_no"));
		map.put("jd_time", map1.get("jd_time"));
		map.put("xd_time", map1.get("xd_time"));
		map.put("wc_time", map1.get("wc_time"));
		map.put("dd_time", map1.get("dd_time"));
		map.put("real_name", map2.get("real_name"));
		map.put("work_avatar", map2.get("work_avatar"));
		map.put("catalog_name", map2.get("catalog_name"));
		map.put("srv_title", map2.get("srv_title"));
		map.put("avatar", map4.get("avatar"));
		if(map.isEmpty()) {
			results.setMessage("暂无数据");//输出：提示信息
			results.setStatus(1);//输出：状态1成功 0失败
		}else {
			results.setResult(map);
			results.setMessage("OK");
			results.setStatus(1);
		}
	}
	// 接口功能：用户端-评价-添加
	public void user_evaluation_set() throws SQLException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String uid= obj_vars.optString("uid"); //用户id
		String oid= obj_vars.optString("oid"); //订单id
		String srv_id= obj_vars.optString("srv_id"); //服务id
		String evl_content= obj_vars.optString("evl_content"); //评价类容
		int comity_level= obj_vars.optInt("comity_level"); //礼仪态度级别 1-5
		int ontime_level= obj_vars.optInt("ontime_level"); //上门及时性级别 1-5
		int service_level= obj_vars.optInt("service_level"); //服务质量级别 1-5
		int charge_level= obj_vars.optInt("charge_level"); //收费标准级别 1-5
		int platform_level= obj_vars.optInt("platform_level"); //平台的满意级别 1-5
		int res= 0;
		Map<String, Object> resultss= new HashMap<>();
		Map<String, Object> data= sqlMapper.public_one_detail("evl_id", "m_evaluation", "oid= "+oid+" and uid= "+uid);
		if(data== null) {
			res=  sqlMapper.insert_or_update("m_evaluation", new HashMap<String, String>() {
				{
					put("oid",oid);
					put("uid",uid);
					put("evl_content",evl_content);
					put("comity_level",String.valueOf(comity_level));
					put("ontime_level",String.valueOf(ontime_level));
					put("service_level",String.valueOf(service_level));
					put("charge_level",String.valueOf(charge_level));
					put("platform_level",String.valueOf(platform_level));
					put("evl_level",String.valueOf(Math.round((comity_level+ontime_level+service_level+charge_level+platform_level)/5)));

				}
			},"");
			resultss.put("evl_id", res);
			res= provider(Integer.parseInt(srv_id),Integer.parseInt(oid),String.valueOf(Math.round((comity_level+ontime_level+service_level+charge_level+platform_level)/5)));
			if(res>0) {
				Systemmessage systemmessage= new Systemmessage();
				systemmessage.setMsg_type_id(Integer.parseInt(oid));
				systemmessage.setMsg_type(103);
				systemmessage.setRole(2);
				systemmessage.setUser_id(Integer.parseInt(sqlMapper.selectOne("select pid from m_order where oid= "+oid).get("pid").toString()));
				systemmessage.setMsg_title("服务消息");
				systemmessage.setMsg_content("您好！"+sqlMapper.selectOne("select CONCAT(left(real_name,1),'师傅') as real_name from p_user where uid= "+uid).get("real_name")+"已经对您进行了评价");
				res= public_wx_systemmessage_set(systemmessage);
				results.setResult(resultss);//输出：评价id
				results.setMessage("操作成功");//输出：提示信息
				results.setStatus(1);//输出：状态1成功 0失败
			}else {
				results.setMessage("操作失败");
				results.setStatus(0);
			}
		}else {
			resultss.put("evl_id", data.get("evl_id"));
			results.setResult(resultss);//输出：评价id
			results.setMessage("评论成功");
			results.setStatus(1);
		}
	}
	// 接口功能：用户端-评价-列表
	public void user_evaluation_get() throws SQLException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String srv_id= obj_vars.optString("srv_id"); //服务id
		int pagenum= obj_vars.optInt("pagenum"); //页数
		Map<String, Object> result= new HashMap<>();
		List<Map<String, Object>> evaluation_list= sqlMapper.public_list_page("a.uid,b.evl_level,b.evl_content,date_format(b.create_time,'%Y-%m-%d %H:%i:%s') as create_time,c.avatar,IFNULL(c.nick_name,'') nick_name,c.real_name ", "m_order a ,m_evaluation b,p_user c", "a.oid= b.oid and a.uid= c.uid and a.srv_id= "+srv_id, "create_time desc", pagenum);
		Map<String, Object> server_detail= sqlMapper.public_one_detail("pid,srv_num,evl_level,evl_num", "s_service", "srv_id= "+srv_id);
		result.put("evaluation_list", evaluation_list);
		if(pagenum== 1||pagenum== 0) {
			result.put("server_detail", server_detail);
		}
		if(!result.isEmpty()) {
			results.setResult(result);
			results.setMessage("OK");
			results.setStatus(1);
		}else {
			results.setMessage("暂无数据");//输出：提示信息
			results.setStatus(1);//输出：状态1成功 0失败
		}
	}
	// 接口功能：用户端-确认上门
	public void user_affirm_visit() throws SQLException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String uid= obj_vars.optString("uid"); //用户id
		String point_id= obj_vars.optString("point_id"); //点单id
		Map<String, Object> map= sqlMapper.public_one_detail("a.srv_id,b.reward_no,b.amount,c.pid", "m_point a left join p_reward b on b.reward_type= 2 and b.business_id= a.point_id and b.status= 2 left join s_service c on c.srv_id= a.srv_id", "point_id= "+point_id+" and uid= "+uid);
		Map<String, String> result= new HashMap<>();
		result.put("uid", uid);
		result.put("status", "进行中");
		result.put("order_no", map.get("reward_no").toString());
		result.put("order_amount", map.get("amount").toString());
		result.put("pid", map.get("pid").toString());
		result.put("point_id", point_id);
		result.put("srv_id", map.get("srv_id").toString());
		int res= sqlMapper.insert_or_update("m_order", result, "");
		result= new HashMap<>();
		result.put("is_trans", "1");
		res= sqlMapper.insert_or_update("m_point", result, "point_id= "+point_id);
		if(res>0) {
			results.setMessage("确认成功");
			results.setStatus(1);
		}else {
			results.setMessage("确认失败");//输出：提示信息
			results.setStatus(0);//输出：状态1成功 0失败
		}
	}
	//服务端接口----------------------开始-----------------------------
	// 接口功能：服务商-申请
	public void provider_apply_set() throws SQLException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String real_name= obj_vars.optString("real_name"); //真实名称
		String phone= obj_vars.optString("phone"); //电话
		String district= obj_vars.optString("district"); //所在地区
		String address= obj_vars.optString("address"); //详细地址
		int res= 0;
		if(!sqlMapper.public_dataifexist("S_PROVIDER_APPLY", "phone= '"+phone+"'")) {
			res=  sqlMapper.insert_or_update("S_PROVIDER_APPLY", new HashMap<String, String>() {
				{
					put("real_name",real_name);
					put("phone",phone);
					put("district",district);
					put("address",address);
				}
			},"");
			if(res>0) {
				results.setMessage("申请成功");//输出：提示信息
				results.setStatus(1);//输出：状态1成功 0失败
			}else {
				results.setMessage("申请失败");
				results.setStatus(0);
			}
		}else {
			results.setMessage("您已申请过了");
			results.setStatus(0);
		}
	}
	// 接口功能：服务商首页(ok)
	public void service_user_home_page_get() throws SQLException {
		Map<String, Object> result =  new HashMap<String, Object>();
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String pid =  obj_vars.optString("pid"); // 服务商id
		String city =  obj_vars.optString("city"); // 首页定位城市
		String area =  obj_vars.optString("area"); // 首页定位区
		String address =  obj_vars.optString("address"); // 首页定位详细地址
		String loc_lng =  obj_vars.optString("loc_lng"); // 首页定位  经度
		String loc_lat =  obj_vars.optString("loc_lat"); // 首页定位 维度
		String cityids= "0";
		String areaids= "0";
		String taskwhere = "";
		result.put("city_id", "");
		Map<String, Object> cityid= sqlMapper.selectOne("select id,spid from p_areas where ifshow= 1 and pid!= 0  and (name= '"+city+"' or alias= '"+city+"')");
		if(cityid!= null) {
			result.put("city_id", cityid.get("id").toString());
		}
		if(!city.isEmpty()&&!pid.isEmpty()) {
			if(cityid!= null) {
				cityids= cityid.get("id").toString();
				Map<String, Object> areaid= sqlMapper.selectOne("select id,spid from p_areas where ifshow= 1 and pid= "+cityid.get("id")+" and LENGTH(spid) =  10 and (name= '"+area+"' or alias= '"+area+"')");
				if(areaid!= null) {
					areaids= areaid.get("id").toString();
				}
			}
			Map<String,String> map= new HashMap<String, String>();
			map.put("loc_city_id", cityids);
			map.put("loc_district_id", areaids);
			map.put("loc_address", address);
			map.put("loc_lng", loc_lng);
			map.put("loc_lat", loc_lat);
			int res= sqlMapper.insert_or_update("s_provider",map, "pid= "+pid);
		}
		if(!cityids.isEmpty()&&!cityids.equals("0")) {
			taskwhere= " and b.city_id= "+cityids+" ";
		}
		String where = "";
		String juli= "";
		if(loc_lat.equals("0")&&loc_lng.equals("0")||loc_lng.isEmpty()||loc_lat.isEmpty()) {
			juli= " '未知' as juli ";
		}else {
			juli= "ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(("+loc_lat+" * PI() / 180 - lat * PI() / 180) / 2),2) + COS("+loc_lat+"  * PI() / 180) * COS(lat * PI() / 180) * POW(SIN(("+loc_lng+" * PI() / 180 - lng * PI() / 180) / 2),2))) * 1000) AS juli ";
 			where= " and a.juli < 20000 ";
		}
		//首页行业显示
		result.put("know_banner", get_setData(202,0));//了解我们
		List<Map<String, Object>> userlocation=  sqlMapper.selectList("SELECT a.* FROM " +
				"(SELECT a.avatar,a.real_name,IFNULL(nick_name,'') nick_name,b.task_title,contact_phone,b.price,b.srv_time,task_id,IFNULL(lng,'') loc_lng,IFNULL(lat,'') loc_lat,b.uid," +
				juli +
				"FROM p_user a,m_task b where b.is_trans= 0 and b.status= 2 and a.uid= b.uid and b.catalog_id in (select catalog_id from s_service where pid= "+pid+")) as a where 1= 1"+ where);
		List<Map<String, Object>> tasklist=  sqlMapper.selectList("SELECT a.* FROM " +
				"(SELECT a.real_name,IFNULL(nick_name,'') nick_name,b.task_title,a.evl_level,date_format(b.create_time,'%Y-%m-%d %H:%i:%s') as create_time,b.task_id,IFNULL(lng,'') loc_lng,IFNULL(lat,'') loc_lat," +
				juli +
				",c.catalog_name,b.task_desc,IFNULL(p_areas.pid,'未知') cityname FROM p_user a,m_task b left join p_areas on district_id= p_areas.id,m_catalog c where b.is_trans= 0 and b.status= 2 and c.catalog_id= b.catalog_id and a.uid= b.uid and b.catalog_id in (select catalog_id from s_service where pid= "+pid+")) as a where 1= 1"+where+" ORDER BY a.create_time desc LIMIT 0,5");
		for (Map<String, Object> map : tasklist) {
			if(!map.get("cityname").equals("未知")) {
				map.put("cityname", sqlMapper.selectOne("select name from p_areas where id= "+map.get("cityname")).get("name"));
			}
		}
		if(userlocation!= null&&userlocation.size()>0) {
			for (Map<String, Object> map : userlocation) {
				map.put("contact_phone", basictool.string_star(map.get("contact_phone").toString(), 3, 7));
			}
		}

		result.put("mayorder", tasklist);
		result.put("userlocation",userlocation);
		result.put("top_banner", get_banner(200));//顶部banner图
		result.put("center_banner", get_banner(201));//中间banner图
		//	result.put("recommend_news", sqlMapper.selectList("select * from m_news"));//热门|推荐
		//	result.put("recommend_user", sqlMapper.selectList("select a.pid,a.work_avatar,b.srv_title,c.catalog_name,a.experience from s_provider a,s_service b,m_catalog c WHERE a.pid in (SELECT task_id from m_task_recommend WHERE rec_type= 1) and a.pid= b.pid  and b.catalog_id= c.catalog_id"));//优质|服务
		result.put("task_list", sqlMapper.selectList("SELECT IFNULL(a.avatar,'') avatar,IFNULL(a.nick_name,'') nick_name,real_name,b.task_desc,b.task_id from p_user a,m_task b where a.uid= b.uid "+taskwhere+" and b.status= 2 ORDER BY b.create_time desc LIMIT 50"));//任务列表
		result.put("provider_list", sqlMapper.selectList("SELECT a.pid,b.srv_id,work_avatar,experience,CONCAT(left(real_name,1),'师傅') as real_name,c.catalog_name from s_provider a ,s_service b,m_catalog c where a.is_forbid= 0 and a.pid= b.pid and b.catalog_id= c.catalog_id ORDER BY a.create_time desc LIMIT 50"));//服务之星
		List<Map<String, Object>> map= sqlMapper.public_list_page("a.oid,IFNULL(b.evl_id,'') evl_id,b.status", "m_order a left join s_evaluation b on a.oid= b.oid", "a.status= '已完成' and IFNULL(a.history_type,'')!= 1 and IFNULL(a.history_type,'')!= 3  and a.is_provider_pay= 1 and a.pid= "+pid,"a.finishtime asc",1);
		for (Map<String, Object> map2 : map) {
			result.put("oid",map2.get("oid"));
			if(!map2.get("evl_id").equals("")) {
				result.put("evl_id", map2.get("evl_id"));
			}
		}
		results.setResult(result);//输出：列表数据
		results.setStatus(1);//输出：状态1成功 0失败
		results.setMessage("ok");//输出：提示信息
	}

	// 接口功能：首页-地图-任务详情 task content
	public  void  task_detail(){
		Map<String, Object> result =  new HashMap<String, Object>();
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String taskid =  obj_vars.optString("taskid"); // 任务id
		String pid =  obj_vars.optString("pid"); //服务商id-非必传
		Integer ifcollect =  0;
		Integer ifCanRobTask =  0;//0-可以抢 1-自己抢 2-别人抢  3-超过三次不能抢
		//基本信息
		Map<String, Object> map =  sqlMapper.selectOne("SELECT uid,task_title,price,c.catalog_name,task_desc,srv_address,contact_name,contact_phone,district_id,srv_time,date_format(t.create_time,'%Y-%m-%d %H:%i:%s') create_time from m_task t " +
				"LEFT JOIN m_catalog c on c.catalog_id =  t.catalog_id" +" where t.task_id= "+taskid);
		Map<String, String> district_id =  getAreaDetailById(map.get("district_id").toString());
		String area =  district_id.get("province")+district_id.get("city")+district_id.get("area")+map.get("srv_address");
		map.put("serviceplace",area);
		map.put("contact_phone", basictool.string_star(map.get("contact_phone").toString(), 3, 7));
		map.put("topimage", get_setData(106,0).get("set_img"));
		//查询用户评分
		Map<String, Object> map1 =  sqlMapper.selectOne("SELECT evl_level,evl_num,uid from p_user u where u.uid = (SELECT uid from m_task where task_id =  "+taskid+" ) ");
		//图片
		List<Map<String, Object>> list =  sqlMapper.selectList("SELECT content from p_content where business_type =  100 and business_id =  " + taskid);
		//查询是否已经订阅
		if(!pid.isEmpty()) {
			Map<String, Object> maps1 =  sqlMapper.selectOne("SELECT COUNT(*) as num from s_collect where task_id = " + taskid + " and pid =  " + pid);
			if (Integer.parseInt(maps1.get("num").toString())>0){
				ifcollect =  1;
			}
			//查询已形成订单个数  判断是否能够下单
			Map<String, Object> maps2 =  sqlMapper.selectOne("SELECT count(*) as sum from m_order where pid = " + pid + " and `status` =  '待确认' and point_id= 0 and is_history =  0");
			if(Integer.parseInt(maps2.get("sum").toString())>= 3){
				ifCanRobTask =  3;
			}

			Map<String, Object> map3= sqlMapper.selectOne("select pid from m_order where task_id= "+taskid+" and IFNULL(is_history,'')!= 1 and IFNULL(history_type,'')!= 1");
			if(map3!= null) {
				if(Integer.parseInt(map3.get("pid").toString())== Integer.parseInt(pid)) {
					ifCanRobTask= 1;
				}else {
					ifCanRobTask= 2;
				}
			}
		}
		result.put("score", map1);//输出：用户分数和评论数量
		result.put("ifCanRobTask",ifCanRobTask);//输出：是否能抢单 1是 0 否
		result.put("ifcollect",ifcollect);//输出：是否已经收藏 1是  0 否
		result.put("detail",map);
		result.put("imgs",list);//输出：任务图片
		result.put("loseTime",10);//输出：任务失效时间
		result.put("maxNum",3);//输出：最多抢订单数
		results.setResult(result);//输出：列表数据
		results.setStatus(1);//输出：状态1成功 0失败
		results.setMessage("ok");//输出：提示信息
	}
	// 接口功能：轮播任务详情
	public  void task_carousel_detail(){
		Map<String, Object> result =  new HashMap<String, Object>();
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String taskid =  obj_vars.optString("taskid"); //任务id
		result= sqlMapper.selectOne("select avatar,real_name,nick_name,c.catalog_name,task_desc,contact_phone,date_format(b.create_time,'%Y-%m-%d %H:%i:%s') create_time from p_user a,m_task b,m_catalog c where c.catalog_id= b.catalog_id and a.uid= b.uid and b.task_id= "+taskid);
		result.put("contact_phone",basictool.string_star(result.get("contact_phone").toString(), 3, 7));
		results.setResult(result);//输出：列表数据
		results.setStatus(1);//输出：状态1成功 0失败
		results.setMessage("ok");//输出：提示信息
	}
	// 接口功能：任务详情-评价列表
	public void get_content_list() throws SQLException{
		Map<String, Object> result =  new HashMap<String, Object>();
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String userid =  obj_vars.optString("userid"); //发布任务用户id
		String taskid =  obj_vars.optString("taskid"); //跳过来前的taskid
		int pagenum =  obj_vars.optInt("pagenum"); //当前页数
		//查询用户评分及评价个数
	/*	sqlMapper.selectOne("se")
		Map<String, Object> map1 =  sqlMapper.selectOne("SELECT avg(e.evl_level) as star,COUNT(*) as count  from s_evaluation e  " +
				"LEFT JOIN m_order o on e.oid =  o.oid  " +
				"LEFT JOIN p_user u on u.uid =  o.uid  " +
				"where u.uid = (SELECT uid from m_task where task_id =  "+taskid+" ) ");*/
		//查询所有评价
		List<Map<String, Object>> maps =  sqlMapper.public_list_page("e.evl_level,e.evl_content,date_format(e.create_time,'%Y-%m-%d %H:%i:%s') as create_time,IFNULL(p.real_name,'某某用户') real_name,p.work_avatar", "s_evaluation e LEFT JOIN m_order o on e.oid =  o.oid LEFT JOIN p_user u on u.uid =  o.uid LEFT JOIN s_provider p on p.pid =  e.pid ", "u.uid = "+userid, "create_time desc", pagenum);
		Map<String, Object> map =  sqlMapper.selectOne("SELECT evl_level,evl_num from p_user where uid = (SELECT uid from m_task where task_id =  " + taskid + ")");
		result.put("evaluation_list",maps);
		result.put("server_detail",map);
		results.setResult(result);//输出：列表数据
		results.setStatus(1);//输出：状态1成功 0失败
		results.setMessage("ok");//输出：提示信息
	}

	// 接口功能：首页-地图-任务详情-收藏
	public void collect_task(){
		Map<String, Object> result =  new HashMap<String, Object>();
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String taskid =  obj_vars.optString("taskid"); //任务id
		String userid =  obj_vars.optString("userid"); // 服务商id
		//insertOrUpdate 入collect表
		HashMap<String, String> map =  new HashMap<>();
		map.put("pid",userid);
		map.put("task_id",taskid);
		//Integer res =  -1;
		try {
			Integer res =  sqlMapper.insert_or_update("s_collect", map, "");

			if (res>-1){
				results.setStatus(1);//输出：状态1成功 0失败
				results.setMessage("ok");//输出：提示信息
			}else {
				results.setStatus(0);//输出：状态1成功 0失败
				results.setMessage("收藏失败");//输出：提示信息
			}
		}catch (Exception e){
			logger.error("collect_task  insert_or_update  error ",e);
		}
	}

	// 接口功能：首页-地图-任务详情-抢单
	public  void rob_task() throws SQLException{
		Map<String, Object> result =  new HashMap<String, Object>();
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String taskid =  obj_vars.optString("taskid"); //任务id
		String userid =  obj_vars.optString("userid"); //服务商id
		Integer ifCanRobTask =  0;//0-可以抢 1-自己抢 2-别人抢  3-超过三次不能抢
		//将当前任务转化为订单 状态为待确认
		Map<String, Object> maps2 =  sqlMapper.selectOne("SELECT count(*) as num from m_order where pid = " + userid + " and `status`=  '待确认' and is_history =  0");
		if(!(Integer.parseInt(maps2.get("num").toString())>= 3)){
		HashMap<String, String> map =  new HashMap<>();
		//从打赏表中获取信息
		Map<String, Object> one =  sqlMapper.selectOne("SELECT user_id,reward_no,amount from p_reward WHERE reward_type= 1 and status= 2 and business_id =  " + taskid);
		Map<String, Object> task= sqlMapper.selectOne("select uid,contact_phone,contact_name,is_trans from m_task where task_id = "+taskid);
		
		//查询已形成订单个数  判断是否能够下单
		
		Map<String, Object> map3= sqlMapper.selectOne("select pid from m_order where task_id= "+taskid+" and IFNULL(is_history,'')!= 1 and IFNULL(history_type,'')!= 1");
		if(map3!= null) {
			if(Integer.parseInt(map3.get("pid").toString())== Integer.parseInt(userid)) {
				ifCanRobTask= 1;
			}else {
				ifCanRobTask= 2;
			}
		}
		result.put("ifCanRobTask", ifCanRobTask);
		if(Integer.parseInt(task.get("is_trans").toString())!= 1) {
			map.put("uid",task.get("uid").toString());
			map.put("status","待确认");
			if(one!= null) {
				map.put("order_no",one.get("reward_no").toString());
				map.put("order_amount",one.get("amount").toString());
			}else {
				map.put("order_no","测试数据没有付款订单号");
				map.put("order_amount","0");
			}
			map.put("pid",userid);
			map.put("task_id",taskid);
			map.put("point_id","0");
			map.put("srv_id", sqlMapper.selectOne("select srv_id from s_service a where pid= "+userid+" and a.catalog_id= (select catalog_id from m_task where task_id= "+taskid+")").get("srv_id").toString());
			int m_order =  sqlMapper.insert_or_update("m_order", map,"");
			int update =  sqlMapper.update("update m_task set is_trans =  (case is_trans when 0 then 1 end) where task_id= "+taskid);

			if (m_order>-1&&update>-1){
				//通知客户单被抢
				Systemmessage systemmessage= new Systemmessage();
				systemmessage.setMsg_type_id(m_order);
				systemmessage.setMsg_type(101);
				systemmessage.setRole(1);
				systemmessage.setUser_id(Integer.parseInt(task.get("uid").toString()));
				systemmessage.setMsg_title("服务消息");
				systemmessage.setMsg_content(sqlMapper.selectOne("select CONCAT(left(real_name,1),'师傅') as real_name from s_provider where pid= "+userid).get("real_name")+"已抢单，请在订单待确认作出回应");
				public_wx_systemmessage_set(systemmessage);
				result.put("contact_phone", task.get("contact_phone"));
				result.put("contact_name", task.get("contact_name"));
				results.setResult(result);//输出：contact_name-联系人 contact_phone-联系电话
				results.setStatus(1);//输出：状态1成功 0失败
				results.setMessage("抢单成功");//输出：提示信息
			}else {
				results.setStatus(0);//输出：状态1成功 0失败
				results.setMessage("抢单失败");//输出：提示信息
			}
		}else {
			result.put("contact_phone", task.get("contact_phone"));
			result.put("contact_name", task.get("contact_name"));
			results.setResult(result);
			results.setStatus(0);//输出：状态1成功 0失败
			results.setMessage("抢单失败,该订单已被抢");//输出：提示信息
		}
		}else {
			results.setStatus(0);//输出：状态1成功 0失败
			results.setMessage("抢单失败,抢单次数不得超过三次");//输出：提示信息
		}
	}


	// 接口功能：我要抢单-服务列表
	public void task_list() throws SQLException{
		Map<String, Object> result =  new HashMap<String, Object>();
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String pid =  obj_vars.optString("pid"); //服务商id
		String city_id =  obj_vars.optString("city_id"); //城市id
		String loc_lng =  obj_vars.optString("loc_lng"); //经度
		String loc_lat =  obj_vars.optString("loc_lat"); //维度
		int pagenum =  obj_vars.optInt("pagenum"); //分页
		String ordertype =  obj_vars.optString("ordertype"); //筛选优先 1 评分从高到低 2 评分从低到高 3 离我最近
		String juli= "";
		String where= "";
		if(loc_lat.equals("0")&&loc_lng.equals("0")||loc_lng.isEmpty()||loc_lat.isEmpty()) {
			juli= " '未知' as juli,";
		}else {
			juli= "ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(("+loc_lat+" * PI() / 180 - loc_lat * PI() / 180) / 2),2) + COS("+loc_lat+"  * PI() / 180) * COS(loc_lat * PI() / 180) * POW(SIN(("+loc_lng+" * PI() / 180 - loc_lng * PI() / 180) / 2),2))) * 1000) AS juli,";
		}
		String orderby= "b.create_time desc";
		switch (ordertype) {
			case "1":
				orderby= "a.evl_level";
				break;
			case "2":
				orderby= "a.evl_level desc";
				break;
			case "3":
				orderby= "juli";
				break;

		}
		if(!city_id.isEmpty()) {
			where+= " and b.city_id= "+city_id;
		}
		List<Map<String, Object>> list= sqlMapper.public_list_page(juli+"b.task_id,a.nick_name,a.real_name,a.evl_level,c.catalog_name,task_desc,date_format(b.create_time,'%Y-%m-%d %H:%i:%s') create_time,b.district_id cityname", "p_user a,m_task b,m_catalog c", "b.status= 2 and a.uid= b.uid and b.catalog_id= c.catalog_id and b.is_trans= 0 and b.catalog_id in (select catalog_id from s_service where pid= "+pid+")"+where, orderby, pagenum);
		List<Map<String, Object>> lists= new ArrayList<>();
		for (Map<String, Object> map : list) {
			map.put("cityname", getAreaDetailById(map.get("cityname").toString()).get("city"));
			lists.add(map);
		}
		results.setResult(lists);//输出：列表数据
		results.setStatus(1);//输出：状态1成功 0失败
		results.setMessage("ok");//输出：提示信息

	}

	// 接口功能：订单-列表(服务商)
	public void order_list(){
		Map<String, Object> result =  new HashMap<String, Object>();
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String status =  obj_vars.optString("status"); //订单状态
		String pid =  obj_vars.optString("userid"); //服务用户id
		String pagenum =  obj_vars.optString("pagenum"); //分页
		int pagesize =  12;
		int limitStart =  (Integer.parseInt(pagenum) - 1) * pagesize;
		List<Map<String, Object>> maps= new ArrayList<>();
		if ("待确认".equals(status)){
			maps =  sqlMapper.selectList("SELECT o.srv_id,o.point_id,o.oid,u.avatar,t.task_id,t.task_title,u.real_name,u.nick_name,c.catalog_name,o.`status` from m_order o " +
					"LEFT JOIN m_task t on o.task_id =  t.task_id " +
					"LEFT JOIN m_catalog c on c.catalog_id =  t.catalog_id " +
					"LEFT JOIN p_user u on u.uid =  t.uid " +
					"where o.task_id !=  0 and o.`status` =  '待确认' and o.pid =  "+pid+" limit "+limitStart+","+pagesize+"");
			//			result.put("orderList",maps);
		}
		if ("进行中".equals(status)){
			maps =  sqlMapper.selectList("(SELECT  o.srv_id,o.point_id,o.oid,t.task_id,o.point_id,t.task_title as title,u.real_name,u.avatar,u.nick_name,c.catalog_name,o.`status` from m_order o  " +
					"LEFT JOIN m_task t on o.task_id =  t.task_id " +
					"LEFT JOIN m_catalog c on c.catalog_id =  t.catalog_id " +
					"LEFT JOIN p_user u on u.uid =  t.uid " +
					"where o.task_id !=  0 and o.`status` =  '进行中' and o.pid= "+pid+")union( " +
					"SELECT o.srv_id,o.point_id,o.oid,o.task_id,o.point_id,s.srv_title as title,u.real_name,u.avatar,u.nick_name,c.catalog_name,o.`status` from m_order o  " +
					"LEFT JOIN p_user u ON o.uid =  u.uid " +
					"LEFT JOIN s_service s ON o.srv_id =  s.srv_id " +
					"LEFT JOIN s_provider p on p.pid =  s.pid " +
					"LEFT JOIN m_catalog c on c.catalog_id =  s.catalog_id " +
					"where o.task_id =  0 and o.`status` =  '进行中' and o.pid= " +pid+
					")  limit "+limitStart+","+pagesize+"");
			//				result.put("orderList",maps);
		}
		if ("已完成".equals(status)){
			maps =  sqlMapper.selectList("(SELECT  o.srv_id,o.point_id,o.oid,t.task_id,o.point_id,t.task_title as title,u.real_name,u.nick_name,u.avatar,c.catalog_name,o.`status` from m_order o  " +
					"LEFT JOIN m_task t on o.task_id =  t.task_id " +
					"LEFT JOIN m_catalog c on c.catalog_id =  t.catalog_id " +
					"LEFT JOIN p_user u on u.uid =  t.uid " +
					"where o.task_id !=  0 and IFNULL(o.history_type,'') != 3 and o.`status` =  '已完成' and o.pid= "+pid+")union( " +
					"SELECT o.srv_id,o.point_id,o.oid,o.task_id,o.point_id,s.srv_title as title,p.real_name,u.nick_name,u.avatar,c.catalog_name,o.`status` from m_order o  " +
					"LEFT JOIN s_service s ON o.srv_id =  s.srv_id " +
					"LEFT JOIN s_provider p on p.pid =  s.pid " +
					"LEFT JOIN m_catalog c on c.catalog_id =  s.catalog_id " +
					"LEFT JOIN p_user u ON o.uid =  u.uid " +
					"where o.task_id =  0 and IFNULL(o.history_type,'') != 3 and o.`status` =  '已完成' and o.pid= " +pid+
					")  limit "+limitStart+","+pagesize+"");
//			result.put("orderList",maps);
		}
		results.setResult(maps);//输出：列表数据
		results.setStatus(1);//输出：状态1成功 0失败
		results.setMessage("ok");//输出：提示信息


	}
	// 接口功能：订单-进行中提醒完成
	public void notify_finished() throws SQLException{
		Map<String, Object> result =  new HashMap<String, Object>();
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String oid =  obj_vars.optString("oid"); //订单id
		String userid =  obj_vars.optString("userid"); //服务商id
		String name =  sqlMapper.selectOne("select CONCAT(left(real_name,1),'师傅') as real_name from s_provider where pid =  "+userid).get("real_name").toString();
		String uid =  sqlMapper.selectOne("select uid from m_order where oid =  "+oid).get("uid").toString();
		Systemmessage systemmessage= new Systemmessage();
		systemmessage.setMsg_type_id(Integer.parseInt(oid));
		systemmessage.setMsg_type(102);
		systemmessage.setRole(1);
		systemmessage.setUser_id(Integer.parseInt(uid));
		systemmessage.setMsg_title("服务消息");
		systemmessage.setMsg_content(name+"提醒您完成订单");
		int insert = public_wx_systemmessage_set(systemmessage);
		if (insert>-1){
			results.setStatus(1);
			results.setMessage("提醒成功");
		}else{
			results.setStatus(0);//输出：状态1成功 0失败
			results.setMessage("操作失败");//输出：提示信息
		}
	}

	// 接口功能：订单-进行中-评价
	public void order_appraise(){
		Map<String, Object> result =  new HashMap<String, Object>();
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String oid =  obj_vars.optString("oid"); //订单id
		String userid =  obj_vars.optString("userid"); //服务商id
		String evl_content =  obj_vars.optString("evl_content"); //评价内容
		int attitude_level =  obj_vars.optInt("attitude_level"); //沟通态度级别
		int desc_level =  obj_vars.optInt("desc_level"); //	需求描述级别
		int pay_level =  obj_vars.optInt("pay_level"); //费用支付级别
		int ontime_level =  obj_vars.optInt("ontime_level"); //	时效性级别
		int cooperation_level =  obj_vars.optInt("cooperation_level"); //	本次合作的满意级别
		Double evl_level =  Double.parseDouble(String.valueOf((attitude_level+desc_level+pay_level+ontime_level+cooperation_level)/5));
		try {
			Map<String, Object> data= sqlMapper.public_one_detail("evl_id,oid,status", "s_evaluation", "oid= "+oid+" and pid= "+userid);
			if(data== null) {
				Map<String, String> map =  new HashMap<String, String>();
				map.put("oid",oid);
				map.put("pid",userid);
				map.put("evl_content",evl_content);
				map.put("attitude_level",String.valueOf(attitude_level));
				map.put("desc_level",String.valueOf(desc_level));
				map.put("pay_level",String.valueOf(pay_level));
				map.put("ontime_level",String.valueOf(ontime_level));
				map.put("cooperation_level",String.valueOf(cooperation_level));
				map.put("evl_level",evl_level.toString());
				int s_evaluation =  sqlMapper.insert_or_update("s_evaluation", map, "");
				if (s_evaluation>-1){
					user(evl_level,Integer.parseInt(oid));
					Systemmessage systemmessage= new Systemmessage();
					systemmessage.setMsg_type_id(Integer.parseInt(oid));
					systemmessage.setMsg_type(203);
					systemmessage.setRole(1);
					systemmessage.setUser_id(Integer.parseInt(sqlMapper.selectOne("select uid from m_order where oid= "+oid).get("uid").toString()));
					systemmessage.setMsg_title("服务消息");
					systemmessage.setMsg_content("您好！"+sqlMapper.selectOne("select CONCAT(left(real_name,1),'师傅') as real_name from s_provider where pid= "+userid).get("real_name")+"已经对您进行了评价");
					public_wx_systemmessage_set(systemmessage);
					Map<String, Object> resultss= new HashMap<>();
					resultss.put("evl_id", s_evaluation);
					results.setResult(resultss);//输出:id
					results.setStatus(1);//输出：状态1成功 0失败
					results.setMessage("评价成功");//输出：提示信息
				}else{
					results.setStatus(0);
					results.setMessage("评价失败");
				}
			}else {
				results.setResult(data);//输出:如果已经评价过了 返回oid和evl_id status= 1时 直接掉起支付界面 status= 2时则只是提示已评论过
				results.setStatus(0);
				results.setMessage("您已评价过该订单");
			}
		}catch (Exception e){
			logger.error(" insert s_evaluation error ");
		}


	}
	// 接口功能：删除任务
	public void delete_task(){
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String task_id =  obj_vars.optString("task_id"); //任务id
		try {
			int m_task =  sqlMapper.delete("delete from m_task where task_id= "+task_id);
			if (m_task>-1){
				results.setStatus(1);//输出：状态1成功 0失败
				results.setMessage("删除成功");//输出：提示信息
			}else{
				results.setStatus(0);
				results.setMessage("删除失败");
			}
		}catch (Exception e){
			logger.error("update order error ");
		}


	}
	// 接口功能：服务商（订单）-已完成-删除订单
	public void delete_order(){
		Map<String, Object> result =  new HashMap<String, Object>();
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String oid =  obj_vars.optString("oid"); //订单id
		Map<String, String> map =  new HashMap<String, String>();
		map.put("is_history","1");
		map.put("history_type","3");
		try {
			int m_order =  sqlMapper.insert_or_update("m_order", map, "oid =  "+oid);
			if (m_order>-1){
				results.setStatus(1);//输出：状态1成功 0失败
				results.setMessage("删除成功");//输出：提示信息
			}else{
				results.setStatus(0);
				results.setMessage("删除失败");
			}
		}catch (Exception e){
			logger.error("update order error ");
		}


	}

	// 接口功能：100到200为用户端；200以上为服务端。100注册协议；101了解我们；105客服热线；200认证热线；201认证地址；202服务端了解我们-详细数据
	public void  get_setData(){
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String set_type= obj_vars.optString("set_type"); //数据类型 100到200为用户端；200以上为服务端。100注册协议；101了解我们；105客服热线；200认证热线；201认证地址；202服务端了解我们-详细数据
		Map<String, Object> list= new HashMap<>();
		if(set_type.equals("100")||set_type.equals("101")||set_type.equals("202")||set_type.equals("105")) {
			list= get_setData(Integer.parseInt(set_type),1);
		}else if(set_type.equals("201")){
			list= get_setData(Integer.parseInt("201"),1);
			String address=  list.get("set_val").toString();
			list= get_setData(Integer.parseInt("200"),1);
			String phone=  list.get("set_val").toString();
			list= new HashMap<>();
			list.put("address", address);
			list.put("phone", phone);
		}else {
			list= get_setData(Integer.parseInt(set_type),0);
		}
		if(list.isEmpty()) {
			results.setMessage("暂无数据");
			results.setStatus(1);
		}else {
			results.setResult(list);//输出：状态1成功 0失败 
			results.setMessage("OK");//输出：提示信息
			results.setStatus(1);//输出：状态1成功 0失败
		}

	}
	// 接口功能：点单id得到师傅信息(ok)
	public void point_provide_data(){
		Map<String, Object> result =  new HashMap<String, Object>();
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String point_id =  obj_vars.optString("point_id"); //点单id
		result= sqlMapper.selectOne("select c.real_name,c.phone from m_point a left join s_service b on a.srv_id= b.srv_id left join s_provider c on b.pid= c.pid where point_id= "+point_id);
		results.setResult(result);//输出：状态1成功 0失败
		results.setMessage("OK");//输出：提示信息
		results.setStatus(1);//输出：状态1成功 0失败
	}
	// 接口功能：服务商分类列表
		public void provide_catalog_get() throws SQLException{
			SqlMapper sqlMapper= new SqlMapper(sqlSessions);
			JSONObject obj_vars =  getObj_vars();
			String pid =  obj_vars.optString("pid"); //服务商id
			List<Map<String, Object>> result= sqlMapper.public_list_column("pid,catalog_name,b.catalog_id", "s_service a left join m_catalog b on a.catalog_id= b.catalog_id", "a.pid= "+pid, "a.create_time desc");
			results.setResult(result);//输出：状态1成功 0失败
			results.setMessage("OK");//输出：提示信息
			results.setStatus(1);//输出：状态1成功 0失败
		}
	// 接口功能：所有打赏提交(ok)
	public void reward_set(){
		Map<String, Object> result =  new HashMap<String, Object>();
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String reward_type =  obj_vars.optString("reward_type"); //打赏类型：1发布任务打赏；2即时点工打赏；3用户评价打赏；4服务商评价打赏
		String business_id =  obj_vars.optString("business_id"); //业务id：每种打赏类型对应的业务id，为发布任务打赏时为任务task_id，为即时点工打赏时为point_id，为用户评价或服务商评价打赏时都为评价evl_id
		String user_type =  obj_vars.optString("user_type"); //打赏用户类型：1用户打赏；2服务商打赏
		String user_id =  obj_vars.optString("user_id"); //打赏用户id
		String amount =  obj_vars.optString("amount"); //打赏金额
		String reward_no= "";
		String catalog_id= "";
		try {
			switch (reward_type) {
				case "1":
					catalog_id= sqlMapper.public_one_detail("catalog_id", "m_task", "task_id= "+business_id).get("catalog_id").toString();
					reward_no= "fbrw"+public_getordercode(user_id);
					break;
				case "2":
					catalog_id= sqlMapper.public_one_detail("b.catalog_id", "m_point a left join s_service b on a.srv_id= b.srv_id", "point_id= "+business_id).get("catalog_id").toString();
					reward_no= "jsdg"+public_getordercode(user_id);
					break;
				case "3":
					catalog_id= sqlMapper.public_one_detail("c.catalog_id", "m_evaluation a left join m_order b on a.oid= b.oid left join s_service c on b.srv_id= c.srv_id", "a.evl_id= "+business_id).get("catalog_id").toString();
					reward_no= "yhpj"+public_getordercode(user_id);
					break;
				case "4":
					catalog_id= sqlMapper.public_one_detail("c.catalog_id", "s_evaluation a left join m_order b on a.oid= b.oid left join s_service c on b.srv_id= c.srv_id", "a.evl_id= "+business_id).get("catalog_id").toString();
					reward_no= "fwspj"+public_getordercode(user_id);
					break;
			}
			Map<String,String> map= new HashMap<>();
			map.put("catalog_id",catalog_id);
			map.put("reward_type",reward_type);
			map.put("business_id",business_id);
			map.put("user_type",user_type);
			map.put("user_id",user_id);
			map.put("amount",amount);
			map.put("reward_no",reward_no);
			int res= sqlMapper.insert_or_update("p_reward",map, "");
			if (res>-1){
				Map<String,Object> newresult= new HashMap<>();
				newresult.put("reward_no", reward_no);
				results.setResult(newresult);//输出：打赏单号
				results.setStatus(1);//输出：状态1成功 0失败
				results.setMessage("保存成功");//输出：提示信息
			}else{
				results.setStatus(0);
				results.setMessage("保存失败");
			}
		}catch (Exception e){
			logger.error(" insert p_reward error ");
		}

	}
	// 接口功能：获取支付信息(共用)(ok)
	public void payinfo_get() throws IOException, SQLException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String reward_no =  obj_vars.optString("reward_no"); // 打赏单号
		String userid =  obj_vars.optString("userid"); // 用户ID
		String paytype =  obj_vars.optString("paytype"); // 支付方式 ，支付宝支付 微信支付 银联支付（直接传中文）
		Map<String, Object> result =  new HashMap<String, Object>();

		int ordertype =  public_getordertype(reward_no);
		if (ordertype== 0) {
			results.setMessage("获取订单信息错误");//输出：提示信息
			results.setStatus(0);//输出：状态1成功 0失败
		} else {
			String totalmoney =  sqlMapper.public_one_column("select amount from p_reward where reward_no= '"+reward_no+"'", "amount");
			switch (paytype) {
				case "支付宝支付":
					result.put("totalmoney", totalmoney);
					result.put("OrderCode", reward_no);//输出：订单编号
					result.put("partner", AlipayConfig.partner);//输出：支付宝身份者ID
					result.put("seller", AlipayConfig.seller);//输出：支付宝seller
					result.put("private_key", AlipayConfig.private_key);//输出：支付宝私钥
					result.put("prepayinfo", AlipayConfig.url_notify); //输出：回调URL
					results.setResult(result);//输出：打赏单号
					results.setStatus(1);//输出：状态1成功 0失败
					results.setMessage("查询成功");//输出：提示信息
					break;
				case "微信支付":
					WeixinPay weixin= new WeixinPay();
					results= weixin.getpaystring(reward_no, totalmoney, request, response);
					break;
				case " 银联支付":

					break;
			}
		}
	}
	// 接口功能：上传图片(只返回路径)(ok)
	public void get_upfile_image() throws IOException, SQLException {
		MultipartHttpServletRequest multipartRequest =  (MultipartHttpServletRequest) request;
		MultipartFile file =  multipartRequest.getFile("image");
		String filename =  FileUpload.writeUploadFile(file,"advert");
		results.setResult(filename);//输出：图片路径
		results.setStatus(1);//输出：状态1成功 0失败
		results.setMessage("上传成功");//输出：提示信息
	}
	// 接口功能：轮播图详情
	public void slideshow_details() throws IOException, SQLException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String adv_id =  obj_vars.optString("adv_id"); // 轮播图id
		try {
			Map<String, Object> map= sqlMapper.public_one_detail("adv_id,data_type,adv_data", "p_adv", "adv_id= "+adv_id);
			if(map.get("data_type").equals(2)) {
				map.put("adv_data", htmlUtils.replace(map.get("adv_data").toString(), filesave_path));
			}
			results.setResult(map);//输出：轮播图详情
			results.setStatus(1);//输出：状态1成功 0失败
			results.setMessage("ok");//输出：提示信息
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
	// 接口功能：评价详情
	public void evaluate_details() throws IOException, SQLException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		Map<String, Object> list= new HashMap<>();
		String evl_id =  obj_vars.optString("evl_id"); // 评价id
		String oid =  obj_vars.optString("oid"); // 订单id
		try {
			if(!evl_id.isEmpty()) {
				Map<String, Object> map= sqlMapper.public_one_detail("oid,pid,evl_content,evl_level,attitude_level,desc_level,pay_level,ontime_level,cooperation_level", "s_evaluation", "evl_id= "+evl_id);
				list.put("evaluate_details",map);
			}
			if(!oid.isEmpty()) {
				Map<String, Object> map= sqlMapper.public_one_detail("b.nick_name,b.real_name,b.evl_level,IFNULL(b.avatar,'') avatar,b.phone,d.catalog_name,IFNULL(e.name,'') cityname", "m_order a left join p_user b on a.uid= b.uid left join s_service c on c.srv_id= a.srv_id left join m_catalog d on c.catalog_id= d.catalog_id left join p_areas e on e.id= loc_city_id", "a.oid= "+oid);
				list.put("user_details",map);
			}
			results.setResult(list);//输出：evaluate_details-评价详情  user_details-用户信息
			results.setStatus(1);//输出：状态1成功 0失败
			results.setMessage("ok");//输出：提示信息
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	// 接口功能：退出登录
	public void out_register() throws IOException, SQLException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String userid =  obj_vars.optString("userid"); // 登录id
		String role =  obj_vars.optString("role"); // 角色1-用户方2-服务商
		int res= 0;
		switch (role) {
			case "1":
				res= sqlMapper.insert_or_update("p_user", new HashMap<String, String>() {
					{
						put("token", "");
						put("DriverID", "");
						put("IOSDriverID", "");
					}
				}, "uid= " + userid);
				break;
			case "2":
				res= sqlMapper.insert_or_update("s_provider", new HashMap<String, String>() {
					{
						put("token", "");
						put("DriverID", "");
						put("IOSDriverID", "");
					}
				}, "pid= " + userid);
				break;
		}
		if(res>0) {
			results.setStatus(1);
			results.setMessage("退出成功");
		}else {
			results.setStatus(0);//输出：状态1成功 0失败
			results.setMessage("退出失败");//输出：提示信息
		}
	}
	// 接口功能：分享链接
		public void download_path_get() throws IOException, SQLException {
				Map<String, Object> map =  new HashMap<>();
				map.put("title", "选我我选");
				map.put("url", app_download);
				map.put("conent", "家庭服务需求，1元发布，1分钟响应！");
				results.setResult(map);//输出：evaluate_details-评价详情  user_details-用户信息
				results.setStatus(1);//输出：状态1成功 0失败
				results.setMessage("ok");//输出：提示信息
		}
		// 接口功能：打赏金额获取
		public void reward_money_get() throws IOException, SQLException {
				SqlMapper sqlMapper= new SqlMapper(sqlSessions);
				JSONObject obj_vars =  getObj_vars();
				String money_type =  obj_vars.optString("money_type"); //打赏类型  1发布任务打赏；2即时点工打赏；3服务商评价打赏
				List<Map<String, Object>> list =  sqlMapper.public_list_column("money,ifforbidden", "p_reward_money_set", "money_type= "+money_type, "money ASC");
				results.setResult(list);//输出：ifforbidden 是否禁用 0-否 1-是
				results.setStatus(1);//输出：状态1成功 0失败
				results.setMessage("ok");//输出：提示信息
		}
		
	// 接口功能：推送测试
	public void tuisong_test() throws IOException, SQLException {
		JSONObject obj_vars =  getObj_vars();
		String IOSDriverID =  obj_vars.optString("IOSDriverID"); // 推送-ios
		String DriverID =  obj_vars.optString("DriverID"); // 推送-Android
		String title =  obj_vars.optString("title"); // 标题
		String content =  obj_vars.optString("content"); // 内容
		Map<String, Object> map= new HashMap<>();
		map.put("type", "1");
		map.put("id", "1");
		try {
			if(!IOSDriverID.isEmpty()) {
				UPushUtils.sendIOSUnicast(IOSDriverID, "通知", title, content, map);
			}
			if(!DriverID.isEmpty()) {
				UPushUtils.sendAndroidUnicast(DriverID, "通知", title, content, map);
			}
		} catch (Exception e) {
			System.out.println("推送失败");
			e.printStackTrace();
		}

	}

	//接口结束********************************************************************************************



	//消息提醒
	public int public_wx_systemmessage_set(Systemmessage systemmessage) throws SQLException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		Map<String, String> data =  new HashMap<String, String>() {
			{
				put("user_id", String.valueOf(systemmessage.getUser_id()));
				put("msg_title", systemmessage.getMsg_title());
				put("role", String.valueOf(systemmessage.getRole()));
				put("msg_content", systemmessage.getMsg_content());
				put("msg_type", String.valueOf(systemmessage.getMsg_type()));
				put("msg_type_id", String.valueOf(systemmessage.getMsg_type_id()));
			}
		};
		int res =  sqlMapper.insert_or_update("p_message", data, "");
		if (res > -1) {
			public_push_systemmessage_set(systemmessage);
		}
		return res;
	}
	//一条推送消息(单播或广播)
	public void public_push_systemmessage_set(Systemmessage systemmessage) throws SQLException {
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		Map<String, Object> map= new HashMap<>();
		map.put("msg_type", systemmessage.getMsg_type());
		map.put("msg_typeid", systemmessage.getMsg_type_id());
		try {
			if (systemmessage.getUser_id() !=  0) {
				Map<String, Object> map_driverid= new HashMap<>();
				if(systemmessage.getRole()== 1) {
					map_driverid =  sqlMapper.selectOne("SELECT IFNULL(IOSDriverID,'') IOSDriverID,IFNULL(DriverID,'') DriverID from p_user WHERE uid= " + systemmessage.getUser_id());
				}else {
					map_driverid =  sqlMapper.selectOne("SELECT IFNULL(IOSDriverID,'') IOSDriverID,IFNULL(DriverID,'') DriverID from s_provider WHERE pid= " + systemmessage.getUser_id());
				}
				if (!map_driverid.get("IOSDriverID").toString().isEmpty()) {
					UPushUtils.sendIOSUnicast(map_driverid.get("IOSDriverID").toString(), "通知", systemmessage.getMsg_title(), systemmessage.getMsg_content(), map);
				}
				if (!map_driverid.get("DriverID").toString().isEmpty()) {
					UPushUtils.sendAndroidUnicast(map_driverid.get("DriverID").toString(), "通知", systemmessage.getMsg_title(), systemmessage.getMsg_content(), map);
				}
			} else {
			}

		} catch (Exception e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}
	}












/*	//订单-详情    与个人的相同
	public void service_order_detail(){
		Map<String, Object> result =  new HashMap<String, Object>();
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		JSONObject obj_vars =  getObj_vars();
		String orderid =  obj_vars.optString("orderid"); //订单id
		String ifpoint =  obj_vars.optString("ifpoint"); //是否点单 1是 0 否 空为否
		String pid =  obj_vars.optString("userid"); //服务用户id
		if ("".equals(ifpoint)||"0".equals(ifpoint)){
			//抢单详情
			Map<String, Object> map =  sqlMapper.selectOne("SELECT t.*,c.catalog_name,date_format(o.create_time,'%Y-%m-%d %H:%i:%s') as create_time,o.order_no,date_format(o.finish_time,'%Y-%m-%d %H:%i:%s') as finish_time from m_order o " +
					"LEFT JOIN m_task t on o.task_id =  t.task_id " +
					"LEFT JOIN m_catalog c on c.catalog_id =  t.catalog_id " +
					"WHERE o.is_history !=  1 and o.oid =  " + orderid);
			results.setResult(map);
			results.setStatus(1);//输出：状态1成功 0失败
			results.setMessage("ok");//输出：提示信息
		}else{
			//点单详情


		}

	}*/

	public int provider(int srv_id,int oid,String nowevl_level) throws SQLException {
		//服务商服务数量和评价等级和评价数量更新
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		Map<String, Object> map= sqlMapper.selectOne("SELECT evl_num,evl_level from s_service a WHERE a.srv_id= "+srv_id);
		Double sumevl_level= Double.parseDouble(map.get("evl_num").toString())*Double.parseDouble(map.get("evl_level").toString());
		nowevl_level= String.valueOf((Double.parseDouble(nowevl_level)+sumevl_level)/(Integer.parseInt(map.get("evl_num").toString())+1));
		Map<String, String> map1= new HashMap<>();
		map1.put("srv_num", String.valueOf(Integer.parseInt(map.get("evl_num").toString())+1));
		map1.put("evl_num", String.valueOf(Integer.parseInt(map.get("evl_num").toString())+1));
		map1.put("evl_level", String.valueOf(Math.round(Double.parseDouble(nowevl_level))));
		int res=  sqlMapper.insert_or_update("s_service",map1, "srv_id= "+srv_id);
		return res;
	}
	public int user(Double evl_level,int oid) throws SQLException {
		//用户服务数量和评价等级和评价数量更新
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		String uid= sqlMapper.selectOne("select uid from m_order where oid= "+oid).get("uid").toString();
		Map<String, Object> map=  sqlMapper.selectOne("select evl_level,evl_num from p_user where uid= "+uid);
		evl_level= evl_level+(Integer.parseInt(map.get("evl_level").toString())*Integer.parseInt(map.get("evl_num").toString()));
		evl_level= evl_level/(Integer.parseInt(map.get("evl_num").toString())+1);
		Map<String, String> map1= new HashMap<>();
		map1.put("evl_num", String.valueOf(Integer.parseInt(map.get("evl_num").toString())+1));
		map1.put("evl_level", String.valueOf(Math.round(evl_level)));
		int res = sqlMapper.insert_or_update("p_user", map1, "uid= " + uid);
		return res;
	}
	public int set_content(int content_type,String content,int business_type,int business_id,int ordid) throws SQLException{
//		内容表：主要存放图文混合的数据；一段文字，一张图片，视频文件，然后排序
//		备注: 内容表：主要存放图文混合的数据；一段文字，一张图片，视频文件，然后排序
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		int res=  sqlMapper.insert_or_update("p_content", new HashMap<String, String>() {
			{
				put("content_type", String.valueOf(content_type));// 	内容类型：1文字；2图片；3视频
				put("content",content);// 	内容类型：1文字；2图片；3视频
				put("business_type", String.valueOf(business_type));//内容类型：用户端：100任务图片；服务端：
				put("business_id", String.valueOf(business_id));// 	和文字、图片和视频类型对应的业务id
				put("ordid", String.valueOf(ordid));// 	和文字、图片和视频类型对应的业务id
			}
		}, "");
		return res;
	}
	public List<Map<String, Object>> get_banner(int ADV_TYPE){
		//轮播图公共方法
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		List<Map<String, Object>> list=   sqlMapper.selectList("select  adv_id,adv_img,adv_type,date_format(create_time,'%Y-%m-%d %H:%i:%s') as create_time  from P_ADV where ADV_TYPE= "+ADV_TYPE);
		return list;
	}
	public Map<String, Object> get_setData(int SET_TYPE,int ifhavadata){
		SqlMapper sqlMapper= new SqlMapper(sqlSessions);
		Map<String, Object> list= new HashMap<>();
		//设置数据
		if(ifhavadata== 0) {
			list=   sqlMapper.selectOne("select  set_id,set_type,set_title,IFNULL(set_img,'') set_img from P_SET  where set_type= "+SET_TYPE);
		}else {
			list=   sqlMapper.selectOne("select  set_id,set_type,set_title,set_img,IFNULL(set_val,'') set_val from P_SET  where set_type= "+SET_TYPE);
			if(!list.get("set_val").equals("")) {
				list.put("set_val", htmlUtils.replace(list.get("set_val").toString(), filesave_path));
			}
		}
		return list;
	}
	public String get_time(Date time){
		//时间转string方法
		SimpleDateFormat format =   new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return  format.format(time);
	}
	// 返回订单号后面的部分/唯一值
	public String public_getordercode(String userid) throws SQLException {
		Random rand =  new Random();
		int randNum =  rand.nextInt(8999) + 1000;
		return System.currentTimeMillis() + Integer.toString(randNum) + userid;
	}
	public Map<String,String> getAreaDetailById(String id) { //传入areaid  返回 map
		SqlMapper sqlMapper =  new SqlMapper(sqlSessions);
		HashMap<String, String> result =  new HashMap<>();
		Map<String, Object> stringObjectMap =  sqlMapper.selectOne("SELECT spid,alias from p_areas where id =  " + id);
		String spid =  stringObjectMap.get("spid").toString();

		if ("0".equals(spid)) {
			//省级
			String province =  stringObjectMap.get("alias").toString();
			result.put("province", province);
			return result;
		} else {
			String[] split =  spid.split("\\|");
			if (split.length ==  1) {
				String city =  stringObjectMap.get("alias").toString();
				//市级
				Map<String, Object> map =  sqlMapper.selectOne("SELECT alias from p_areas where id =  " + split[0]);
				String area =  map.get("alias").toString();
				result.put("city", city);
				result.put("area", area);
				return result;
			}
			if (split.length ==  2) {
				String area =  stringObjectMap.get("alias").toString();
				//区级
				Map<String, Object> map =  sqlMapper.selectOne("SELECT alias from p_areas where id =  " + split[0]);
				Map<String, Object> map1 =  sqlMapper.selectOne("SELECT alias from p_areas where id =  " + split[1]);
				String province =  map.get("alias").toString();
				String city =  map1.get("alias").toString();
				result.put("province", province);
				result.put("city", city);
				result.put("area", area);
				return result;
			}

		}
		return  null;
	}
	// 通过ordercode返回订单场景(result:1发布任务,2及时点单,3用户评价,4服务商评价)
	public int public_getordertype(String ordercode) throws SQLException {
		int result =  0;
		if (ordercode.indexOf("fbrw") > -1) {//发布任务
			result =  1;
		} else if (ordercode.indexOf("jsdg") > -1) {//及时点单
			result =  2;
		} else if (ordercode.indexOf("yhpj") > -1) {//用户评价
			result =  3;
		} else if (ordercode.indexOf("fwspj") > -1) {//服务商评价
			result =  4;
		}

		return result;
	}
}
